| Directory: | ./ |
|---|---|
| File: | sql/field.cc |
| Date: | 2022-11-26 14:12:44 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 4102 | 4699 | 87.3% |
| Branches: | 3162 | 5205 | 60.7% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | Copyright (c) 2000, 2022, Oracle and/or its affiliates. | ||
| 3 | |||
| 4 | This program is free software; you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License, version 2.0, | ||
| 6 | as published by the Free Software Foundation. | ||
| 7 | |||
| 8 | This program is also distributed with certain software (including | ||
| 9 | but not limited to OpenSSL) that is licensed under separate terms, | ||
| 10 | as designated in a particular file or component or in included license | ||
| 11 | documentation. The authors of MySQL hereby grant you an additional | ||
| 12 | permission to link the program and your derivative works with the | ||
| 13 | separately licensed software that they have included with MySQL. | ||
| 14 | |||
| 15 | This program is distributed in the hope that it will be useful, | ||
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | GNU General Public License, version 2.0, for more details. | ||
| 19 | |||
| 20 | You should have received a copy of the GNU General Public License | ||
| 21 | along with this program; if not, write to the Free Software | ||
| 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include "sql/field.h" | ||
| 26 | |||
| 27 | #include <float.h> | ||
| 28 | #include <stddef.h> | ||
| 29 | |||
| 30 | #include "m_ctype.h" | ||
| 31 | #include "my_config.h" | ||
| 32 | #ifdef HAVE_SYS_TIME_H | ||
| 33 | #include <sys/time.h> | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #include <algorithm> | ||
| 37 | #include <cmath> // isnan | ||
| 38 | #include <memory> // unique_ptr | ||
| 39 | #include <optional> | ||
| 40 | |||
| 41 | #include "decimal.h" | ||
| 42 | #include "m_string.h" | ||
| 43 | #include "my_alloc.h" | ||
| 44 | #include "my_byteorder.h" | ||
| 45 | #include "my_compare.h" | ||
| 46 | #include "my_compiler.h" | ||
| 47 | #include "my_dbug.h" | ||
| 48 | #include "my_double2ulonglong.h" | ||
| 49 | #include "my_sqlcommand.h" | ||
| 50 | #include "myisampack.h" | ||
| 51 | #include "sql-common/json_binary.h" // json_binary::serialize | ||
| 52 | #include "sql-common/json_dom.h" // Json_dom, Json_wrapper | ||
| 53 | #include "sql/create_field.h" | ||
| 54 | #include "sql/current_thd.h" | ||
| 55 | #include "sql/dd/cache/dictionary_client.h" | ||
| 56 | #include "sql/dd/types/table.h" | ||
| 57 | #include "sql/dd_table_share.h" // dd_get_old_field_type | ||
| 58 | #include "sql/derror.h" // ER_THD | ||
| 59 | #include "sql/filesort.h" // change_double_for_sort | ||
| 60 | #include "sql/gis/rtree_support.h" // get_mbr_from_store | ||
| 61 | #include "sql/gis/srid.h" | ||
| 62 | #include "sql/handler.h" | ||
| 63 | #include "sql/item.h" | ||
| 64 | #include "sql/item_json_func.h" // ensure_utf8mb4 | ||
| 65 | #include "sql/item_timefunc.h" // Item_func_now_local | ||
| 66 | #include "sql/join_optimizer/bit_utils.h" | ||
| 67 | #include "sql/json_diff.h" // Json_diff_vector | ||
| 68 | #include "sql/key.h" | ||
| 69 | #include "sql/log_event.h" // class Table_map_log_event | ||
| 70 | #include "sql/my_decimal.h" | ||
| 71 | #include "sql/mysqld.h" // log_10 | ||
| 72 | #include "sql/protocol.h" | ||
| 73 | #include "sql/psi_memory_key.h" | ||
| 74 | #include "sql/rpl_replica.h" // rpl_master_has_bug | ||
| 75 | #include "sql/rpl_rli.h" // Relay_log_info | ||
| 76 | #include "sql/spatial.h" // Geometry | ||
| 77 | #include "sql/sql_base.h" | ||
| 78 | #include "sql/sql_class.h" // THD | ||
| 79 | #include "sql/sql_exception_handler.h" // handle_std_exception | ||
| 80 | #include "sql/sql_lex.h" | ||
| 81 | #include "sql/sql_time.h" // str_to_datetime_with_warn | ||
| 82 | #include "sql/sql_tmp_table.h" // create_tmp_field | ||
| 83 | #include "sql/srs_fetcher.h" | ||
| 84 | #include "sql/stateless_allocator.h" | ||
| 85 | #include "sql/strfunc.h" // find_type2 | ||
| 86 | #include "sql/system_variables.h" | ||
| 87 | #include "sql/time_zone_common.h" | ||
| 88 | #include "sql/transaction_info.h" | ||
| 89 | #include "sql/tztime.h" // Time_zone | ||
| 90 | #include "template_utils.h" // pointer_cast | ||
| 91 | #include "typelib.h" | ||
| 92 | |||
| 93 | namespace dd { | ||
| 94 | class Spatial_reference_system; | ||
| 95 | } // namespace dd | ||
| 96 | |||
| 97 | using std::max; | ||
| 98 | using std::min; | ||
| 99 | |||
| 100 | #define FLAGSTR(V, F) ((V) & (F) ? #F " " : "") | ||
| 101 | |||
| 102 | // Maximum allowed exponent value for converting string to decimal | ||
| 103 | #define MAX_EXPONENT 1024 | ||
| 104 | |||
| 105 | /** | ||
| 106 | Static variables | ||
| 107 | */ | ||
| 108 | const char field_separator = ','; | ||
| 109 | uchar Field::dummy_null_buffer = ' '; | ||
| 110 | |||
| 111 | #define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER | ||
| 112 | #define LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE 128 | ||
| 113 | #define DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE 128 | ||
| 114 | #define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \ | ||
| 115 | ((ulong)((1LL << std::min(arg, 4U) * 8) - 1LL)) | ||
| 116 | |||
| 117 | /* | ||
| 118 | Rules for merging different types of fields in UNION | ||
| 119 | |||
| 120 | NOTE: to avoid 256*256 table, gap in table types numeration is skipped | ||
| 121 | following #defines describe that gap and how to canculate number of fields | ||
| 122 | and index of field in this array. | ||
| 123 | */ | ||
| 124 | #define FIELDTYPE_TEAR_FROM (MYSQL_TYPE_BIT + 1) | ||
| 125 | #define FIELDTYPE_TEAR_TO (243 - 1) | ||
| 126 | #define FIELDTYPE_NUM (FIELDTYPE_TEAR_FROM + (255 - FIELDTYPE_TEAR_TO)) | ||
| 127 | |||
| 128 | namespace { | ||
| 129 | /** | ||
| 130 | Predicate to determine if a field type change prevents alter | ||
| 131 | from being done inplace. | ||
| 132 | |||
| 133 | @param from - existing Field object. | ||
| 134 | @param to - Create_field object describing new version of field. | ||
| 135 | |||
| 136 | @return true if alter cannot be done inplace due to specified | ||
| 137 | condition, false otherwise. | ||
| 138 | */ | ||
| 139 | 338284 | bool sql_type_prevents_inplace(const Field &from, const Create_field &to) { | |
| 140 |
1/2✓ Branch 0 taken 338284 times.
✗ Branch 1 not taken.
|
338284 | DBUG_TRACE; |
| 141 |
1/2✓ Branch 0 taken 338284 times.
✗ Branch 1 not taken.
|
676568 | return to.sql_type != from.real_type(); |
| 142 | 338284 | } | |
| 143 | |||
| 144 | /** | ||
| 145 | Predicate to determine if a length change prevents alter from being | ||
| 146 | done inplace. Length cannot decrease and cannot cross the 256 byte | ||
| 147 | row format barrier. | ||
| 148 | |||
| 149 | @param from - existing Field object. | ||
| 150 | @param to - Create_field object describing new version of field. | ||
| 151 | |||
| 152 | @return true if alter cannot be done inplace due to specified | ||
| 153 | condition, false otherwise. | ||
| 154 | */ | ||
| 155 | 118233 | bool length_prevents_inplace(const Field &from, const Create_field &to) { | |
| 156 |
1/2✓ Branch 0 taken 118233 times.
✗ Branch 1 not taken.
|
118233 | DBUG_TRACE; |
| 157 |
8/14✓ Branch 0 taken 118233 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 118233 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 118232 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
|
118233 | DBUG_PRINT( |
| 158 | "inplace", | ||
| 159 | ("from:%p, to.field:%p, to.field->row_pack_length():%u, " | ||
| 160 | "to.max_display_width_in_bytes():%zu", | ||
| 161 | &from, to.field, to.field ? to.field->row_pack_length() : (uint)-1, | ||
| 162 | to.max_display_width_in_bytes())); | ||
| 163 | |||
| 164 |
4/6✓ Branch 0 taken 118233 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 118233 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 705 times.
✓ Branch 5 taken 117528 times.
|
118233 | if (to.pack_length() < from.pack_length()) { |
| 165 |
3/16✓ Branch 0 taken 705 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 705 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 705 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
705 | DBUG_PRINT( |
| 166 | "inplace", | ||
| 167 | ("decreasing pack_length from %u to %zu, -> true for '%s'", | ||
| 168 | from.pack_length(), to.pack_length(), current_thd->query().str)); | ||
| 169 | 705 | return true; | |
| 170 | } | ||
| 171 | |||
| 172 |
8/10✓ Branch 0 taken 117528 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25503 times.
✓ Branch 3 taken 92025 times.
✓ Branch 4 taken 25503 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 316 times.
✓ Branch 7 taken 25187 times.
✓ Branch 8 taken 316 times.
✓ Branch 9 taken 117212 times.
|
117528 | if (to.max_display_width_in_bytes() >= 256 && from.row_pack_length() < 256) { |
| 173 |
3/16✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 316 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 316 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
316 | DBUG_PRINT("inplace", |
| 174 | ("row_pack_length increases past the 256 threshold, from %u to " | ||
| 175 | "%zu, -> true for '%s'", | ||
| 176 | from.row_pack_length(), to.max_display_width_in_bytes(), | ||
| 177 | current_thd->query().str)); | ||
| 178 |
3/12✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 316 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 316 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
316 | DBUG_PRINT("inplace", |
| 179 | ("from:%p, to.field:%p, to.field->row_pack_length():%u", &from, | ||
| 180 | to.field, to.field ? to.field->row_pack_length() : (uint)-1)); | ||
| 181 | 316 | return true; | |
| 182 | } | ||
| 183 |
5/8✓ Branch 0 taken 117212 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 117212 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 117211 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
117212 | DBUG_PRINT("inplace", ("-> false")); |
| 184 | 117212 | return false; | |
| 185 | 118233 | } | |
| 186 | |||
| 187 | /** | ||
| 188 | Predicate to determine if a charset change prevents alter from being | ||
| 189 | done inplace. | ||
| 190 | |||
| 191 | For changes other than the following, we can immediately reject using | ||
| 192 | the inplace algorithm: | ||
| 193 | |||
| 194 | - Changing collation while keeping the charset. | ||
| 195 | - Changing any charset to the binary charset. | ||
| 196 | - Changing utf8mb3 to utf8mb4. | ||
| 197 | |||
| 198 | @note The changes listed above are potentially acceptable if the field | ||
| 199 | is not indexed in the target table. This information is not available | ||
| 200 | here, and is checked later in fill_alter_inplace_info(). | ||
| 201 | |||
| 202 | @note ASCII cannot be converted to UTF-8 inplace because inserting | ||
| 203 | non-ascii values into an ASCII column only trigger a warning not an | ||
| 204 | error. | ||
| 205 | |||
| 206 | @param from - existing Field object. | ||
| 207 | @param to - Create_field object describing new version of field. | ||
| 208 | |||
| 209 | @return true if alter cannot be done inplace due to specified | ||
| 210 | condition, false otherwise. | ||
| 211 | */ | ||
| 212 | 207588 | bool charset_prevents_inplace(const Field_str &from, const Create_field &to) { | |
| 213 |
1/2✓ Branch 0 taken 207588 times.
✗ Branch 1 not taken.
|
207588 | DBUG_TRACE; |
| 214 | |||
| 215 |
6/8✓ Branch 0 taken 207588 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 207588 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1984 times.
✓ Branch 5 taken 205604 times.
✓ Branch 6 taken 205621 times.
✓ Branch 7 taken 1967 times.
|
209572 | if (my_charset_same(to.charset, from.charset()) || |
| 216 |
3/4✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 1967 times.
|
1984 | my_charset_same(to.charset, &my_charset_bin)) { |
| 217 | 205621 | return false; | |
| 218 | } | ||
| 219 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 1847 times.
|
2087 | return (0 != strcmp(to.charset->csname, MY_UTF8MB4) || |
| 220 |
3/4✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78 times.
✓ Branch 3 taken 42 times.
|
2087 | 0 != strcmp(from.charset()->csname, "utf8mb3")); |
| 221 | 207588 | } | |
| 222 | |||
| 223 | /** | ||
| 224 | Predicate to determine if the difference between a Field and the | ||
| 225 | new Create_field prevents alter from being done | ||
| 226 | inplace. Convenience wrapper for the preceding predicates. | ||
| 227 | |||
| 228 | @param from - existing Field object. | ||
| 229 | @param to - Create_field object describing new version of field. | ||
| 230 | |||
| 231 | @return true if alter cannot be done inplace due to specified | ||
| 232 | condition, false otherwise. | ||
| 233 | */ | ||
| 234 | 119979 | bool change_prevents_inplace(const Field_str &from, const Create_field &to) { | |
| 235 |
1/2✓ Branch 0 taken 119979 times.
✗ Branch 1 not taken.
|
119979 | DBUG_TRACE; |
| 236 |
1/2✓ Branch 0 taken 119979 times.
✗ Branch 1 not taken.
|
119979 | return sql_type_prevents_inplace(from, to) || |
| 237 |
5/6✓ Branch 0 taken 118233 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 117212 times.
✓ Branch 3 taken 1021 times.
✓ Branch 4 taken 117208 times.
✓ Branch 5 taken 4 times.
|
235445 | length_prevents_inplace(from, to) || |
| 238 | // Changing column format to/from compressed or changing associated | ||
| 239 | // compression dictionary must result in table rebuild | ||
| 240 |
2/2✓ Branch 0 taken 118233 times.
✓ Branch 1 taken 1746 times.
|
355424 | from.has_different_compression_attributes_with(to) || |
| 241 |
3/4✓ Branch 0 taken 117208 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1919 times.
✓ Branch 3 taken 115289 times.
|
237187 | charset_prevents_inplace(from, to); |
| 242 | 119979 | } | |
| 243 | } // namespace | ||
| 244 | |||
| 245 | 23143580 | inline int field_type2index(enum_field_types field_type) { | |
| 246 | 23143580 | field_type = real_type_to_type(field_type); | |
| 247 |
3/4✓ Branch 0 taken 3106562 times.
✓ Branch 1 taken 20037018 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3106562 times.
|
23143580 | assert(field_type < FIELDTYPE_TEAR_FROM || field_type > FIELDTYPE_TEAR_TO); |
| 248 | 23143580 | return (field_type < FIELDTYPE_TEAR_FROM | |
| 249 |
2/2✓ Branch 0 taken 3106562 times.
✓ Branch 1 taken 20037018 times.
|
23143580 | ? field_type |
| 250 | 3106562 | : ((int)FIELDTYPE_TEAR_FROM) + (field_type - FIELDTYPE_TEAR_TO) - | |
| 251 | 23143580 | 1); | |
| 252 | } | ||
| 253 | |||
| 254 | static enum_field_types field_types_merge_rules[FIELDTYPE_NUM][FIELDTYPE_NUM] = | ||
| 255 | { | ||
| 256 | /* MYSQL_TYPE_DECIMAL -> */ | ||
| 257 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 258 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL, | ||
| 259 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 260 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL, | ||
| 261 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 262 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE, | ||
| 263 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 264 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 265 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 266 | MYSQL_TYPE_DECIMAL, MYSQL_TYPE_DECIMAL, | ||
| 267 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 268 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 269 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 270 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 271 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 272 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 273 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 274 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_INVALID, | ||
| 275 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 276 | MYSQL_TYPE_DECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 277 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 278 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 279 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 280 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 281 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 282 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 283 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 284 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 285 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 286 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 287 | /* MYSQL_TYPE_TINY -> */ | ||
| 288 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 289 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY, | ||
| 290 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 291 | MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, | ||
| 292 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 293 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, | ||
| 294 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 295 | MYSQL_TYPE_TINY, MYSQL_TYPE_VARCHAR, | ||
| 296 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 297 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24, | ||
| 298 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 299 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 300 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 301 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY, | ||
| 302 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 303 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 304 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 305 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID, | ||
| 306 | // MYSQL_TYPE_BOOL MYSQL_TYPE_TINY | ||
| 307 | MYSQL_TYPE_TINY, MYSQL_TYPE_VARCHAR, | ||
| 308 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 309 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 310 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 311 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 312 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 313 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 314 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 315 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 316 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 317 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 318 | /* MYSQL_TYPE_SHORT -> */ | ||
| 319 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 320 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_SHORT, | ||
| 321 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 322 | MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, | ||
| 323 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 324 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, | ||
| 325 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 326 | MYSQL_TYPE_SHORT, MYSQL_TYPE_VARCHAR, | ||
| 327 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 328 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24, | ||
| 329 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 330 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 331 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 332 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_SHORT, | ||
| 333 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 334 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 335 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 336 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID, | ||
| 337 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 338 | MYSQL_TYPE_SHORT, MYSQL_TYPE_VARCHAR, | ||
| 339 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 340 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 341 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 342 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 343 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 344 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 345 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 346 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 347 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 348 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 349 | /* MYSQL_TYPE_LONG -> */ | ||
| 350 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 351 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_LONG, | ||
| 352 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 353 | MYSQL_TYPE_LONG, MYSQL_TYPE_LONG, | ||
| 354 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 355 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE, | ||
| 356 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 357 | MYSQL_TYPE_LONG, MYSQL_TYPE_VARCHAR, | ||
| 358 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 359 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONG, | ||
| 360 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 361 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 362 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 363 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONG, | ||
| 364 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 365 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 366 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 367 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID, | ||
| 368 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 369 | MYSQL_TYPE_LONG, MYSQL_TYPE_VARCHAR, | ||
| 370 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 371 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 372 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 373 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 374 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 375 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 376 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 377 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 378 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 379 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 380 | /* MYSQL_TYPE_FLOAT -> */ | ||
| 381 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 382 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_FLOAT, | ||
| 383 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 384 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, | ||
| 385 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 386 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, | ||
| 387 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 388 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_VARCHAR, | ||
| 389 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 390 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_FLOAT, | ||
| 391 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 392 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 393 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 394 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_FLOAT, | ||
| 395 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 396 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 397 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 398 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_INVALID, | ||
| 399 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 400 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_VARCHAR, | ||
| 401 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 402 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR, | ||
| 403 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 404 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 405 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 406 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 407 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 408 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 409 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 410 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 411 | /* MYSQL_TYPE_DOUBLE -> */ | ||
| 412 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 413 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE, | ||
| 414 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 415 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE, | ||
| 416 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 417 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE, | ||
| 418 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 419 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR, | ||
| 420 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 421 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE, | ||
| 422 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 423 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 424 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 425 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_DOUBLE, | ||
| 426 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 427 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 428 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 429 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_INVALID, | ||
| 430 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 431 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR, | ||
| 432 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 433 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR, | ||
| 434 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 435 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 436 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 437 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 438 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 439 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 440 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 441 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 442 | /* MYSQL_TYPE_NULL -> */ | ||
| 443 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 444 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY, | ||
| 445 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 446 | MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, | ||
| 447 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 448 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, | ||
| 449 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 450 | MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP, | ||
| 451 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 452 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG, | ||
| 453 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 454 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_TIME, | ||
| 455 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 456 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR, | ||
| 457 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 458 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, | ||
| 459 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 460 | MYSQL_TYPE_BIT, MYSQL_TYPE_INVALID, | ||
| 461 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 462 | MYSQL_TYPE_BOOL, MYSQL_TYPE_JSON, | ||
| 463 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 464 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_ENUM, | ||
| 465 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 466 | MYSQL_TYPE_SET, MYSQL_TYPE_TINY_BLOB, | ||
| 467 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 468 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 469 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 470 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 471 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 472 | MYSQL_TYPE_STRING, MYSQL_TYPE_GEOMETRY}, | ||
| 473 | /* MYSQL_TYPE_TIMESTAMP -> */ | ||
| 474 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 475 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 476 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 477 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 478 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 479 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 480 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 481 | MYSQL_TYPE_TIMESTAMP, MYSQL_TYPE_TIMESTAMP, | ||
| 482 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 483 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 484 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 485 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME, | ||
| 486 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 487 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR, | ||
| 488 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 489 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR, | ||
| 490 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 491 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID, | ||
| 492 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 493 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 494 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 495 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 496 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 497 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 498 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 499 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 500 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 501 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 502 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 503 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 504 | /* MYSQL_TYPE_LONGLONG -> */ | ||
| 505 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 506 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_LONGLONG, | ||
| 507 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 508 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG, | ||
| 509 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 510 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE, | ||
| 511 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 512 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_VARCHAR, | ||
| 513 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 514 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG, | ||
| 515 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 516 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 517 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 518 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONGLONG, | ||
| 519 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 520 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, | ||
| 521 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 522 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID, | ||
| 523 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 524 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_VARCHAR, | ||
| 525 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 526 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 527 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 528 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 529 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 530 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 531 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 532 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 533 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 534 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 535 | /* MYSQL_TYPE_INT24 -> */ | ||
| 536 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 537 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_INT24, | ||
| 538 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 539 | MYSQL_TYPE_INT24, MYSQL_TYPE_LONG, | ||
| 540 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 541 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, | ||
| 542 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 543 | MYSQL_TYPE_INT24, MYSQL_TYPE_VARCHAR, | ||
| 544 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 545 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24, | ||
| 546 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 547 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 548 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 549 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INT24, | ||
| 550 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 551 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, | ||
| 552 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 553 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID, | ||
| 554 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 555 | MYSQL_TYPE_INT24, MYSQL_TYPE_VARCHAR, | ||
| 556 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 557 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 558 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 559 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 560 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 561 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 562 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 563 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 564 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 565 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 566 | /* MYSQL_TYPE_DATE -> */ | ||
| 567 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 568 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 569 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 570 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 571 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 572 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 573 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 574 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME, | ||
| 575 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 576 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 577 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 578 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME, | ||
| 579 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 580 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR, | ||
| 581 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 582 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, | ||
| 583 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 584 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID, | ||
| 585 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 586 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 587 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 588 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 589 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 590 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 591 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 592 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 593 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 594 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 595 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 596 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 597 | /* MYSQL_TYPE_TIME -> */ | ||
| 598 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 599 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 600 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 601 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 602 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 603 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 604 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 605 | MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME, | ||
| 606 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 607 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 608 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 609 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_TIME, | ||
| 610 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 611 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR, | ||
| 612 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 613 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, | ||
| 614 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 615 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID, | ||
| 616 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 617 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 618 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 619 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 620 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 621 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 622 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 623 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 624 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 625 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 626 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 627 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 628 | /* MYSQL_TYPE_DATETIME -> */ | ||
| 629 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 630 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 631 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 632 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 633 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 634 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 635 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 636 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME, | ||
| 637 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 638 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 639 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 640 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME, | ||
| 641 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 642 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR, | ||
| 643 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 644 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR, | ||
| 645 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 646 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID, | ||
| 647 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 648 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 649 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 650 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 651 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 652 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 653 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 654 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 655 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 656 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 657 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 658 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 659 | /* MYSQL_TYPE_YEAR -> */ | ||
| 660 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 661 | MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, | ||
| 662 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 663 | MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, | ||
| 664 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 665 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, | ||
| 666 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 667 | MYSQL_TYPE_YEAR, MYSQL_TYPE_VARCHAR, | ||
| 668 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 669 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24, | ||
| 670 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 671 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 672 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 673 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_YEAR, | ||
| 674 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 675 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 676 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 677 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID, | ||
| 678 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 679 | MYSQL_TYPE_SHORT, MYSQL_TYPE_VARCHAR, | ||
| 680 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 681 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 682 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 683 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 684 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 685 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 686 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 687 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 688 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 689 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 690 | /* MYSQL_TYPE_NEWDATE -> */ | ||
| 691 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 692 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 693 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 694 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 695 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 696 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 697 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 698 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME, | ||
| 699 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 700 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 701 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 702 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME, | ||
| 703 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 704 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR, | ||
| 705 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 706 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, | ||
| 707 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 708 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID, | ||
| 709 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 710 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 711 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 712 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 713 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 714 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 715 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 716 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 717 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 718 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 719 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 720 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 721 | /* MYSQL_TYPE_VARCHAR -> */ | ||
| 722 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 723 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 724 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 725 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 726 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 727 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 728 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 729 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 730 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 731 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 732 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 733 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 734 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 735 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 736 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 737 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 738 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 739 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID, | ||
| 740 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 741 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 742 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 743 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 744 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 745 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 746 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 747 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 748 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 749 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 750 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 751 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR}, | ||
| 752 | /* MYSQL_TYPE_BIT -> */ | ||
| 753 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 754 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_LONGLONG, | ||
| 755 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 756 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG, | ||
| 757 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 758 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE, | ||
| 759 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 760 | MYSQL_TYPE_BIT, MYSQL_TYPE_VARCHAR, | ||
| 761 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 762 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG, | ||
| 763 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 764 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 765 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 766 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONGLONG, | ||
| 767 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 768 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 769 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 770 | MYSQL_TYPE_BIT, MYSQL_TYPE_INVALID, | ||
| 771 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 772 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_VARCHAR, | ||
| 773 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 774 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 775 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 776 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 777 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 778 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 779 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 780 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 781 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 782 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 783 | /* MYSQL_TYPE_INVALID -> */ | ||
| 784 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 785 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 786 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 787 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 788 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 789 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 790 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 791 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 792 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 793 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 794 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 795 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 796 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 797 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 798 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 799 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 800 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 801 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 802 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 803 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 804 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 805 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 806 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 807 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 808 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 809 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 810 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 811 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID, | ||
| 812 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 813 | MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID}, | ||
| 814 | /* MYSQL_TYPE_BOOL -> */ | ||
| 815 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 816 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY, | ||
| 817 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 818 | MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, | ||
| 819 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 820 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, | ||
| 821 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 822 | MYSQL_TYPE_BOOL, MYSQL_TYPE_VARCHAR, | ||
| 823 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 824 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24, | ||
| 825 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 826 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 827 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 828 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_SHORT, | ||
| 829 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 830 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 831 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 832 | MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID, | ||
| 833 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 834 | MYSQL_TYPE_BOOL, MYSQL_TYPE_VARCHAR, | ||
| 835 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 836 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 837 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 838 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 839 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 840 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 841 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 842 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 843 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 844 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 845 | /* MYSQL_TYPE_JSON -> */ | ||
| 846 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 847 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 848 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 849 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 850 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 851 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 852 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 853 | MYSQL_TYPE_JSON, MYSQL_TYPE_VARCHAR, | ||
| 854 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 855 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 856 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 857 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 858 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 859 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 860 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 861 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 862 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 863 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID, | ||
| 864 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 865 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_JSON, | ||
| 866 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 867 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 868 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 869 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONG_BLOB, | ||
| 870 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 871 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 872 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 873 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 874 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 875 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 876 | /* MYSQL_TYPE_NEWDECIMAL -> */ | ||
| 877 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 878 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL, | ||
| 879 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 880 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL, | ||
| 881 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 882 | MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE, | ||
| 883 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 884 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 885 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 886 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL, | ||
| 887 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 888 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 889 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 890 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_NEWDECIMAL, | ||
| 891 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 892 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 893 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 894 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_INVALID, | ||
| 895 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 896 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 897 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 898 | MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, | ||
| 899 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 900 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 901 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 902 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 903 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 904 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 905 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 906 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 907 | /* MYSQL_TYPE_ENUM -> */ | ||
| 908 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 909 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 910 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 911 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 912 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 913 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 914 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 915 | MYSQL_TYPE_ENUM, MYSQL_TYPE_VARCHAR, | ||
| 916 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 917 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 918 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 919 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 920 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 921 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 922 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 923 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 924 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 925 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID, | ||
| 926 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 927 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 928 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 929 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 930 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 931 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 932 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 933 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 934 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 935 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 936 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 937 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 938 | /* MYSQL_TYPE_SET -> */ | ||
| 939 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 940 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 941 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 942 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 943 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 944 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 945 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 946 | MYSQL_TYPE_SET, MYSQL_TYPE_VARCHAR, | ||
| 947 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 948 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 949 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 950 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 951 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 952 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 953 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 954 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 955 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 956 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID, | ||
| 957 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 958 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 959 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 960 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 961 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 962 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 963 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 964 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 965 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 966 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 967 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 968 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR}, | ||
| 969 | /* MYSQL_TYPE_TINY_BLOB -> */ | ||
| 970 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 971 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB, | ||
| 972 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 973 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB, | ||
| 974 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 975 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB, | ||
| 976 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 977 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB, | ||
| 978 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 979 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB, | ||
| 980 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 981 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB, | ||
| 982 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 983 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB, | ||
| 984 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 985 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB, | ||
| 986 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 987 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_INVALID, | ||
| 988 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 989 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 990 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 991 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB, | ||
| 992 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 993 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB, | ||
| 994 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 995 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 996 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 997 | MYSQL_TYPE_BLOB, MYSQL_TYPE_TINY_BLOB, | ||
| 998 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 999 | MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB}, | ||
| 1000 | /* MYSQL_TYPE_MEDIUM_BLOB -> */ | ||
| 1001 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 1002 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB, | ||
| 1003 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 1004 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB, | ||
| 1005 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 1006 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB, | ||
| 1007 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 1008 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB, | ||
| 1009 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 1010 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB, | ||
| 1011 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 1012 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB, | ||
| 1013 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 1014 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB, | ||
| 1015 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 1016 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB, | ||
| 1017 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 1018 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_INVALID, | ||
| 1019 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 1020 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1021 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 1022 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB, | ||
| 1023 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 1024 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB, | ||
| 1025 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 1026 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1027 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 1028 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB, | ||
| 1029 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 1030 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB}, | ||
| 1031 | /* MYSQL_TYPE_LONG_BLOB -> */ | ||
| 1032 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 1033 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1034 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 1035 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1036 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 1037 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1038 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 1039 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1040 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 1041 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1042 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 1043 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1044 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 1045 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1046 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 1047 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1048 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 1049 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_INVALID, | ||
| 1050 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 1051 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1052 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 1053 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1054 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 1055 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1056 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 1057 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1058 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 1059 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1060 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 1061 | MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB}, | ||
| 1062 | /* MYSQL_TYPE_BLOB -> */ | ||
| 1063 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 1064 | MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB, | ||
| 1065 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 1066 | MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB, | ||
| 1067 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 1068 | MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB, | ||
| 1069 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 1070 | MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB, | ||
| 1071 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 1072 | MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB, | ||
| 1073 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 1074 | MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB, | ||
| 1075 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 1076 | MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB, | ||
| 1077 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 1078 | MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB, | ||
| 1079 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 1080 | MYSQL_TYPE_BLOB, MYSQL_TYPE_INVALID, | ||
| 1081 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 1082 | MYSQL_TYPE_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1083 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 1084 | MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB, | ||
| 1085 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 1086 | MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB, | ||
| 1087 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 1088 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1089 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 1090 | MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB, | ||
| 1091 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 1092 | MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB}, | ||
| 1093 | /* MYSQL_TYPE_VAR_STRING -> */ | ||
| 1094 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 1095 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1096 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 1097 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1098 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 1099 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1100 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 1101 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1102 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 1103 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1104 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 1105 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1106 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 1107 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1108 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 1109 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1110 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 1111 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID, | ||
| 1112 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 1113 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1114 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 1115 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1116 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 1117 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 1118 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 1119 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1120 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 1121 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 1122 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 1123 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR}, | ||
| 1124 | /* MYSQL_TYPE_STRING -> */ | ||
| 1125 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 1126 | MYSQL_TYPE_STRING, MYSQL_TYPE_STRING, | ||
| 1127 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 1128 | MYSQL_TYPE_STRING, MYSQL_TYPE_STRING, | ||
| 1129 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 1130 | MYSQL_TYPE_STRING, MYSQL_TYPE_STRING, | ||
| 1131 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 1132 | MYSQL_TYPE_STRING, MYSQL_TYPE_STRING, | ||
| 1133 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 1134 | MYSQL_TYPE_STRING, MYSQL_TYPE_STRING, | ||
| 1135 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 1136 | MYSQL_TYPE_STRING, MYSQL_TYPE_STRING, | ||
| 1137 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 1138 | MYSQL_TYPE_STRING, MYSQL_TYPE_STRING, | ||
| 1139 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 1140 | MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR, | ||
| 1141 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 1142 | MYSQL_TYPE_STRING, MYSQL_TYPE_INVALID, | ||
| 1143 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 1144 | MYSQL_TYPE_STRING, MYSQL_TYPE_STRING, | ||
| 1145 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 1146 | MYSQL_TYPE_STRING, MYSQL_TYPE_STRING, | ||
| 1147 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 1148 | MYSQL_TYPE_STRING, MYSQL_TYPE_TINY_BLOB, | ||
| 1149 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 1150 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1151 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 1152 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 1153 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 1154 | MYSQL_TYPE_STRING, MYSQL_TYPE_STRING}, | ||
| 1155 | /* MYSQL_TYPE_GEOMETRY -> */ | ||
| 1156 | {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 1157 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1158 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 1159 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1160 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 1161 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1162 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 1163 | MYSQL_TYPE_GEOMETRY, MYSQL_TYPE_VARCHAR, | ||
| 1164 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 1165 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1166 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 1167 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1168 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 1169 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1170 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 1171 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1172 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 1173 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID, | ||
| 1174 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 1175 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1176 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 1177 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR, | ||
| 1178 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 1179 | MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB, | ||
| 1180 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 1181 | MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, | ||
| 1182 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 1183 | MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR, | ||
| 1184 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 1185 | MYSQL_TYPE_STRING, MYSQL_TYPE_GEOMETRY}}; | ||
| 1186 | |||
| 1187 | 9623 | bool pre_validate_value_generator_expr(Item *expression, const char *name, | |
| 1188 | Value_generator_source source) { | ||
| 1189 | enum error_type { ER_GENERATED_ROW, ER_NAMED_FUNCTION, MAX_ERROR }; | ||
| 1190 | 9623 | int error_code_map[][MAX_ERROR] = { | |
| 1191 | // Generated column | ||
| 1192 | {ER_GENERATED_COLUMN_ROW_VALUE, | ||
| 1193 | ER_GENERATED_COLUMN_NAMED_FUNCTION_IS_NOT_ALLOWED}, | ||
| 1194 | // Default expression | ||
| 1195 | {ER_DEFAULT_VAL_GENERATED_ROW_VALUE, | ||
| 1196 | ER_DEFAULT_VAL_GENERATED_NAMED_FUNCTION_IS_NOT_ALLOWED}, | ||
| 1197 | // Check constraint | ||
| 1198 | {ER_CHECK_CONSTRAINT_ROW_VALUE, | ||
| 1199 | ER_CHECK_CONSTRAINT_NAMED_FUNCTION_IS_NOT_ALLOWED}}; | ||
| 1200 | |||
| 1201 | // ROW values are not allowed | ||
| 1202 |
3/4✓ Branch 0 taken 9623 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 9618 times.
|
9623 | if (expression->type() == Item::ROW_ITEM) { |
| 1203 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | my_error(error_code_map[source][ER_GENERATED_ROW], MYF(0), name); |
| 1204 | 5 | return true; | |
| 1205 | } | ||
| 1206 | |||
| 1207 | Check_function_as_value_generator_parameters checker_args( | ||
| 1208 | 9618 | error_code_map[source][ER_NAMED_FUNCTION], source); | |
| 1209 | |||
| 1210 |
3/4✓ Branch 0 taken 9618 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
✓ Branch 3 taken 9420 times.
|
9618 | if (expression->walk(&Item::check_function_as_value_generator, |
| 1211 | enum_walk::SUBQUERY_POSTFIX, | ||
| 1212 | pointer_cast<uchar *>(&checker_args))) { | ||
| 1213 |
1/2✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
|
198 | my_error(checker_args.err_code, MYF(0), name, |
| 1214 | checker_args.banned_function_name); | ||
| 1215 | 198 | return true; | |
| 1216 | } | ||
| 1217 | |||
| 1218 | 9420 | return false; | |
| 1219 | } | ||
| 1220 | |||
| 1221 | /** | ||
| 1222 | Set field to temporary value NULL. | ||
| 1223 | */ | ||
| 1224 | 2895837 | void Field::set_tmp_null() { | |
| 1225 | 2895837 | m_is_tmp_null = true; | |
| 1226 | |||
| 1227 | 2895837 | m_check_for_truncated_fields_saved = current_thd->check_for_truncated_fields; | |
| 1228 | 2920151 | } | |
| 1229 | |||
| 1230 | ✗ | uint Field::is_equal(const Create_field *new_field) const { | |
| 1231 | ✗ | return (real_type() == new_field->sql_type); | |
| 1232 | } | ||
| 1233 | /** | ||
| 1234 | Return type of which can carry value of both given types in UNION result. | ||
| 1235 | |||
| 1236 | @param a type for merging | ||
| 1237 | @param b type for merging | ||
| 1238 | |||
| 1239 | @return | ||
| 1240 | type of field | ||
| 1241 | */ | ||
| 1242 | |||
| 1243 | 6923803 | enum_field_types Field::field_type_merge(enum_field_types a, | |
| 1244 | enum_field_types b) { | ||
| 1245 |
2/4✓ Branch 0 taken 6923803 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6923803 times.
✗ Branch 3 not taken.
|
6923803 | assert(a != MYSQL_TYPE_INVALID && b != MYSQL_TYPE_INVALID); |
| 1246 | 6923803 | return field_types_merge_rules[field_type2index(a)][field_type2index(b)]; | |
| 1247 | } | ||
| 1248 | |||
| 1249 | static Item_result field_types_result_type[FIELDTYPE_NUM] = { | ||
| 1250 | // MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY | ||
| 1251 | DECIMAL_RESULT, INT_RESULT, | ||
| 1252 | // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG | ||
| 1253 | INT_RESULT, INT_RESULT, | ||
| 1254 | // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE | ||
| 1255 | REAL_RESULT, REAL_RESULT, | ||
| 1256 | // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP | ||
| 1257 | STRING_RESULT, STRING_RESULT, | ||
| 1258 | // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24 | ||
| 1259 | INT_RESULT, INT_RESULT, | ||
| 1260 | // MYSQL_TYPE_DATE MYSQL_TYPE_TIME | ||
| 1261 | STRING_RESULT, STRING_RESULT, | ||
| 1262 | // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR | ||
| 1263 | STRING_RESULT, INT_RESULT, | ||
| 1264 | // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR | ||
| 1265 | STRING_RESULT, STRING_RESULT, | ||
| 1266 | // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID | ||
| 1267 | INT_RESULT, INVALID_RESULT, | ||
| 1268 | // Unused entries: <17>-<242> | ||
| 1269 | // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON | ||
| 1270 | INT_RESULT, STRING_RESULT, | ||
| 1271 | // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM | ||
| 1272 | DECIMAL_RESULT, STRING_RESULT, | ||
| 1273 | // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB | ||
| 1274 | STRING_RESULT, STRING_RESULT, | ||
| 1275 | // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB | ||
| 1276 | STRING_RESULT, STRING_RESULT, | ||
| 1277 | // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING | ||
| 1278 | STRING_RESULT, STRING_RESULT, | ||
| 1279 | // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY | ||
| 1280 | STRING_RESULT, STRING_RESULT}; | ||
| 1281 | |||
| 1282 | /** | ||
| 1283 | Convert Field::geometry_type to the corresponding Geometry::wkbType. | ||
| 1284 | |||
| 1285 | @param t The geometry_type to convert | ||
| 1286 | |||
| 1287 | @return The corresponding Geometry::wkbType, or | ||
| 1288 | Geometry::wkb_invalid_type if there's not suitable type. | ||
| 1289 | */ | ||
| 1290 | 2498519 | static Geometry::wkbType geometry_type_to_wkb_type(Field::geometry_type t) { | |
| 1291 |
8/9✓ Branch 0 taken 1105382 times.
✓ Branch 1 taken 1391391 times.
✓ Branch 2 taken 351 times.
✓ Branch 3 taken 449 times.
✓ Branch 4 taken 204 times.
✓ Branch 5 taken 242 times.
✓ Branch 6 taken 270 times.
✓ Branch 7 taken 233 times.
✗ Branch 8 not taken.
|
2498519 | switch (t) { |
| 1292 | 1105382 | case Field::GEOM_GEOMETRY: | |
| 1293 | 1105382 | return Geometry::wkb_invalid_type; | |
| 1294 | 1391391 | case Field::GEOM_POINT: | |
| 1295 | 1391391 | return Geometry::wkb_point; | |
| 1296 | 351 | case Field::GEOM_LINESTRING: | |
| 1297 | 351 | return Geometry::wkb_linestring; | |
| 1298 | 449 | case Field::GEOM_POLYGON: | |
| 1299 | 449 | return Geometry::wkb_polygon; | |
| 1300 | 204 | case Field::GEOM_MULTIPOINT: | |
| 1301 | 204 | return Geometry::wkb_multipoint; | |
| 1302 | 242 | case Field::GEOM_MULTILINESTRING: | |
| 1303 | 242 | return Geometry::wkb_multilinestring; | |
| 1304 | 270 | case Field::GEOM_MULTIPOLYGON: | |
| 1305 | 270 | return Geometry::wkb_multipolygon; | |
| 1306 | 233 | case Field::GEOM_GEOMETRYCOLLECTION: | |
| 1307 | 233 | return Geometry::wkb_geometrycollection; | |
| 1308 | ✗ | default: | |
| 1309 | ✗ | assert(0); | |
| 1310 | return Geometry::wkb_invalid_type; | ||
| 1311 | } | ||
| 1312 | } | ||
| 1313 | |||
| 1314 | /* | ||
| 1315 | Test if the given string contains important data: | ||
| 1316 | not spaces for character string, | ||
| 1317 | or any data for binary string. | ||
| 1318 | |||
| 1319 | SYNOPSIS | ||
| 1320 | test_if_important_data() | ||
| 1321 | cs Character set | ||
| 1322 | str String to test | ||
| 1323 | strend String end | ||
| 1324 | |||
| 1325 | RETURN | ||
| 1326 | false - If string does not have important data | ||
| 1327 | true - If string has some important data | ||
| 1328 | */ | ||
| 1329 | |||
| 1330 | 42509427 | static bool test_if_important_data(const CHARSET_INFO *cs, const char *str, | |
| 1331 | const char *strend) { | ||
| 1332 |
2/2✓ Branch 0 taken 42508441 times.
✓ Branch 1 taken 986 times.
|
42509427 | if (cs != &my_charset_bin) |
| 1333 | 42508441 | str += cs->cset->scan(cs, str, strend, MY_SEQ_SPACES); | |
| 1334 | 42518164 | return (str < strend); | |
| 1335 | } | ||
| 1336 | |||
| 1337 | /** | ||
| 1338 | Function to compare two unsigned integers for their relative order. | ||
| 1339 | Used below. In an anonymous namespace to not clash with definitions | ||
| 1340 | in other files. | ||
| 1341 | */ | ||
| 1342 | |||
| 1343 | namespace { | ||
| 1344 | |||
| 1345 | 216272 | int compare(unsigned int a, unsigned int b) { | |
| 1346 |
2/2✓ Branch 0 taken 113 times.
✓ Branch 1 taken 216159 times.
|
216272 | if (a < b) return -1; |
| 1347 |
2/2✓ Branch 0 taken 98 times.
✓ Branch 1 taken 216061 times.
|
216159 | if (b < a) return 1; |
| 1348 | 216061 | return 0; | |
| 1349 | } | ||
| 1350 | |||
| 1351 | } // namespace | ||
| 1352 | |||
| 1353 | /** | ||
| 1354 | Detect Item_result by given field type of UNION merge result. | ||
| 1355 | |||
| 1356 | @param field_type given field type | ||
| 1357 | |||
| 1358 | @return | ||
| 1359 | Item_result (type of internal MySQL expression result) | ||
| 1360 | */ | ||
| 1361 | |||
| 1362 | 9287504 | Item_result Field::result_merge_type(enum_field_types field_type) { | |
| 1363 | 9287504 | return field_types_result_type[field_type2index(field_type)]; | |
| 1364 | } | ||
| 1365 | |||
| 1366 | /***************************************************************************** | ||
| 1367 | Static help functions | ||
| 1368 | *****************************************************************************/ | ||
| 1369 | |||
| 1370 | /** | ||
| 1371 | Output a warning for erroneous conversion of strings to numerical | ||
| 1372 | values. For use with ER_TRUNCATED_WRONG_VALUE[_FOR_FIELD] | ||
| 1373 | |||
| 1374 | @param thd THD object | ||
| 1375 | @param str pointer to string that failed to be converted | ||
| 1376 | @param length length of string | ||
| 1377 | @param cs charset for string | ||
| 1378 | @param typestr string describing type converted to | ||
| 1379 | @param error error value to output | ||
| 1380 | @param field_name (for *_FOR_FIELD) name of field | ||
| 1381 | @param row_num (for *_FOR_FIELD) row number | ||
| 1382 | */ | ||
| 1383 | 1005 | static void push_numerical_conversion_warning( | |
| 1384 | THD *thd, const char *str, uint length, const CHARSET_INFO *cs, | ||
| 1385 | const char *typestr, int error, const char *field_name = "UNKNOWN", | ||
| 1386 | ulong row_num = 0) { | ||
| 1387 | char buf[std::max(std::max(DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE, | ||
| 1388 | LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE), | ||
| 1389 | DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE)]; | ||
| 1390 | |||
| 1391 | 1005 | String tmp(buf, sizeof(buf), cs); | |
| 1392 |
1/2✓ Branch 0 taken 1005 times.
✗ Branch 1 not taken.
|
1005 | tmp.copy(str, length, cs); |
| 1393 |
3/6✓ Branch 0 taken 1005 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1005 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1005 times.
✗ Branch 5 not taken.
|
1005 | push_warning_printf(thd, Sql_condition::SL_WARNING, error, |
| 1394 | ER_THD_NONCONST(thd, error), typestr, tmp.c_ptr(), | ||
| 1395 | field_name, row_num); | ||
| 1396 | 1005 | } | |
| 1397 | |||
| 1398 | /** | ||
| 1399 | Emits a warning for the decimal conversion error. May modify | ||
| 1400 | dec_value if there was conversion overflow or bad number. | ||
| 1401 | |||
| 1402 | @param thd Thread handler | ||
| 1403 | @param field Field to operate on | ||
| 1404 | @param dec_error decimal library return code | ||
| 1405 | (E_DEC_* see include/decimal.h) | ||
| 1406 | @param [in,out] dec_value Decimal value returned by conversion function. | ||
| 1407 | @param from Value converted from | ||
| 1408 | @param length Length of 'from' | ||
| 1409 | @param charset_arg Charset of 'from' | ||
| 1410 | */ | ||
| 1411 | 123 | static void set_decimal_warning(THD *thd, Field_new_decimal *field, | |
| 1412 | int dec_error, my_decimal *dec_value, | ||
| 1413 | const char *from, size_t length, | ||
| 1414 | const CHARSET_INFO *charset_arg) { | ||
| 1415 |
3/4✓ Branch 0 taken 20 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 81 times.
✗ Branch 3 not taken.
|
123 | switch (dec_error) { |
| 1416 | 20 | case E_DEC_TRUNCATED: | |
| 1417 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | field->set_warning(Sql_condition::SL_NOTE, WARN_DATA_TRUNCATED, 1); |
| 1418 | 42 | break; | |
| 1419 | 22 | case E_DEC_OVERFLOW: | |
| 1420 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | field->set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, |
| 1421 | 1); | ||
| 1422 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | field->set_value_on_overflow(dec_value, dec_value->sign()); |
| 1423 | 22 | break; | |
| 1424 | 81 | case E_DEC_BAD_NUM: | |
| 1425 |
1/2✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
|
81 | ErrConvString errmsg(from, length, charset_arg); |
| 1426 | 81 | const Diagnostics_area *da = thd->get_stmt_da(); | |
| 1427 |
2/4✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 81 times.
✗ Branch 3 not taken.
|
81 | push_warning_printf( |
| 1428 | thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, | ||
| 1429 | ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), "decimal", | ||
| 1430 | errmsg.ptr(), field->field_name, da->current_row_for_condition()); | ||
| 1431 | 81 | my_decimal_set_zero(dec_value); | |
| 1432 | } | ||
| 1433 | 123 | } | |
| 1434 | |||
| 1435 | /** | ||
| 1436 | Copy string with optional character set conversion. | ||
| 1437 | |||
| 1438 | This calls helper function well_formed_copy_nchars to copy string | ||
| 1439 | with optional character set conversion. Specially, it checks if | ||
| 1440 | the ASCII code point exceeds code range. If YES, it allows the | ||
| 1441 | input but raises a warning. | ||
| 1442 | |||
| 1443 | @param to_cs Character set of "to" string | ||
| 1444 | @param to Store result here | ||
| 1445 | @param to_length Maximum length of "to" string | ||
| 1446 | @param from_cs From character set | ||
| 1447 | @param from Copy from here | ||
| 1448 | @param from_length Length of from string | ||
| 1449 | @param nchars Copy not more that nchars characters | ||
| 1450 | @param well_formed_error_pos Return position when "from" is not well | ||
| 1451 | formed or NULL otherwise. | ||
| 1452 | @param cannot_convert_error_pos Return position where a not convertible | ||
| 1453 | character met, or NULL otherwise. | ||
| 1454 | @param from_end_pos Return position where scanning of "from" | ||
| 1455 | string stopped. | ||
| 1456 | |||
| 1457 | @retval length of bytes copied to 'to' | ||
| 1458 | */ | ||
| 1459 | |||
| 1460 | 776700622 | static size_t field_well_formed_copy_nchars( | |
| 1461 | const CHARSET_INFO *to_cs, char *to, size_t to_length, | ||
| 1462 | const CHARSET_INFO *from_cs, const char *from, size_t from_length, | ||
| 1463 | size_t nchars, const char **well_formed_error_pos, | ||
| 1464 | const char **cannot_convert_error_pos, const char **from_end_pos) { | ||
| 1465 | 776700622 | size_t res = well_formed_copy_nchars( | |
| 1466 | to_cs, to, to_length, from_cs, from, from_length, nchars, | ||
| 1467 | well_formed_error_pos, cannot_convert_error_pos, from_end_pos); | ||
| 1468 | 776701098 | return res; | |
| 1469 | } | ||
| 1470 | |||
| 1471 | /** | ||
| 1472 | Check whether a field type can be partially indexed by a key. | ||
| 1473 | |||
| 1474 | This is a static method, rather than a virtual function, because we need | ||
| 1475 | to check the type of a non-Field in mysql_alter_table(). | ||
| 1476 | |||
| 1477 | @param type field type | ||
| 1478 | |||
| 1479 | @retval | ||
| 1480 | true Type can have a prefixed key | ||
| 1481 | @retval | ||
| 1482 | false Type can not have a prefixed key | ||
| 1483 | */ | ||
| 1484 | |||
| 1485 | 261962 | bool Field::type_can_have_key_part(enum enum_field_types type) { | |
| 1486 |
2/2✓ Branch 0 taken 207330 times.
✓ Branch 1 taken 54632 times.
|
261962 | switch (type) { |
| 1487 | 207330 | case MYSQL_TYPE_VARCHAR: | |
| 1488 | case MYSQL_TYPE_TINY_BLOB: | ||
| 1489 | case MYSQL_TYPE_MEDIUM_BLOB: | ||
| 1490 | case MYSQL_TYPE_LONG_BLOB: | ||
| 1491 | case MYSQL_TYPE_BLOB: | ||
| 1492 | case MYSQL_TYPE_VAR_STRING: | ||
| 1493 | case MYSQL_TYPE_STRING: | ||
| 1494 | case MYSQL_TYPE_GEOMETRY: | ||
| 1495 | 207330 | return true; | |
| 1496 | 54632 | default: | |
| 1497 | 54632 | return false; | |
| 1498 | } | ||
| 1499 | } | ||
| 1500 | |||
| 1501 | /** | ||
| 1502 | Numeric fields base class constructor. | ||
| 1503 | */ | ||
| 1504 | 24009047 | Field_num::Field_num(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, | |
| 1505 | uchar null_bit_arg, uchar auto_flags_arg, | ||
| 1506 | const char *field_name_arg, uint8 dec_arg, bool zero_arg, | ||
| 1507 | 24009047 | bool unsigned_arg) | |
| 1508 | : Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg, | ||
| 1509 | field_name_arg), | ||
| 1510 | 24009055 | unsigned_flag(unsigned_arg), | |
| 1511 | 24009055 | dec(dec_arg), | |
| 1512 | 24009047 | zerofill(zero_arg) { | |
| 1513 |
2/2✓ Branch 0 taken 30841 times.
✓ Branch 1 taken 23978214 times.
|
24009055 | if (zerofill) set_flag(ZEROFILL_FLAG); |
| 1514 |
2/2✓ Branch 0 taken 16042719 times.
✓ Branch 1 taken 7966336 times.
|
24009055 | if (unsigned_flag) set_flag(UNSIGNED_FLAG); |
| 1515 | 24009055 | } | |
| 1516 | |||
| 1517 | 80126 | void Field_num::prepend_zeros(String *value) const { | |
| 1518 | int diff; | ||
| 1519 |
2/2✓ Branch 0 taken 27956 times.
✓ Branch 1 taken 52170 times.
|
80126 | if ((diff = (int)(field_length - value->length())) > 0) { |
| 1520 | 27956 | const bool error = value->mem_realloc(field_length); | |
| 1521 |
1/2✓ Branch 0 taken 27956 times.
✗ Branch 1 not taken.
|
27956 | if (!error) { |
| 1522 | 27956 | memmove(value->ptr() + field_length - value->length(), value->ptr(), | |
| 1523 | value->length()); | ||
| 1524 | 27956 | memset(value->ptr(), '0', diff); | |
| 1525 | 27956 | value->length(field_length); | |
| 1526 | } | ||
| 1527 | } | ||
| 1528 | 80126 | } | |
| 1529 | |||
| 1530 | /** | ||
| 1531 | Test if given number is a int. | ||
| 1532 | |||
| 1533 | @todo | ||
| 1534 | Make this multi-byte-character safe | ||
| 1535 | |||
| 1536 | @param cs Character set | ||
| 1537 | @param str String to test | ||
| 1538 | @param length Length of 'str' | ||
| 1539 | @param int_end Pointer to char after last used digit | ||
| 1540 | @param error Return code from strntoull10rnd() | ||
| 1541 | |||
| 1542 | @note | ||
| 1543 | This is called after one has called strntoull10rnd() function. | ||
| 1544 | |||
| 1545 | @return TYPE_OK, TYPE_ERR_BAD_VALUE or TYPE_WARN_TRUNCATED | ||
| 1546 | */ | ||
| 1547 | |||
| 1548 | 42525033 | type_conversion_status Field_num::check_int(const CHARSET_INFO *cs, | |
| 1549 | const char *str, size_t length, | ||
| 1550 | const char *int_end, int error) { | ||
| 1551 | /* Test if we get an empty string or wrong integer */ | ||
| 1552 |
3/4✓ Branch 0 taken 42531110 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10724 times.
✓ Branch 3 taken 42520386 times.
|
42525033 | if (str == int_end || error == MY_ERRNO_EDOM) { |
| 1553 |
1/2✓ Branch 0 taken 386 times.
✗ Branch 1 not taken.
|
4647 | THD *thd = current_thd; |
| 1554 |
1/2✓ Branch 0 taken 386 times.
✗ Branch 1 not taken.
|
386 | ErrConvString err(str, length, cs); |
| 1555 |
2/4✓ Branch 0 taken 386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 386 times.
✗ Branch 3 not taken.
|
386 | push_warning_printf( |
| 1556 | thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, | ||
| 1557 | ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), "integer", err.ptr(), | ||
| 1558 | field_name, thd->get_stmt_da()->current_row_for_condition()); | ||
| 1559 | 386 | return TYPE_ERR_BAD_VALUE; | |
| 1560 | } | ||
| 1561 | /* Test if we have garbage at the end of the given string. */ | ||
| 1562 |
2/2✓ Branch 0 taken 4025 times.
✓ Branch 1 taken 42517484 times.
|
42520386 | if (test_if_important_data(cs, int_end, str + length)) { |
| 1563 | 4025 | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); | |
| 1564 | 625 | return TYPE_WARN_TRUNCATED; | |
| 1565 | } | ||
| 1566 | 42517484 | return TYPE_OK; | |
| 1567 | } | ||
| 1568 | |||
| 1569 | /* | ||
| 1570 | Convert a string to an integer, then check bounds. | ||
| 1571 | |||
| 1572 | SYNOPSIS | ||
| 1573 | Field_num::get_int | ||
| 1574 | cs Character set | ||
| 1575 | from String to convert | ||
| 1576 | len Length of the string | ||
| 1577 | rnd OUT longlong value | ||
| 1578 | unsigned_max max unsigned value | ||
| 1579 | signed_min min signed value | ||
| 1580 | signed_max max signed value | ||
| 1581 | |||
| 1582 | DESCRIPTION | ||
| 1583 | The function calls strntoull10rnd() to get an integer value then | ||
| 1584 | check bounds and errors returned. In case of any error a warning | ||
| 1585 | is raised. | ||
| 1586 | |||
| 1587 | @return TYPE_OK, TYPE_WARN_OUT_OF_RANGE, TYPE_ERR_BAD_VALUE or | ||
| 1588 | TYPE_WARN_TRUNCATED | ||
| 1589 | */ | ||
| 1590 | |||
| 1591 | 45458425 | type_conversion_status Field_num::get_int(const CHARSET_INFO *cs, | |
| 1592 | const char *from, size_t len, | ||
| 1593 | longlong *rnd, ulonglong unsigned_max, | ||
| 1594 | longlong signed_min, | ||
| 1595 | longlong signed_max) { | ||
| 1596 | const char *end; | ||
| 1597 | int error; | ||
| 1598 | |||
| 1599 |
1/2✓ Branch 0 taken 45499271 times.
✗ Branch 1 not taken.
|
45458425 | *rnd = (longlong)cs->cset->strntoull10rnd(cs, from, len, is_unsigned(), &end, |
| 1600 | &error); | ||
| 1601 |
2/2✓ Branch 0 taken 2416807 times.
✓ Branch 1 taken 43087065 times.
|
45499271 | if (is_unsigned()) { |
| 1602 |
5/6✓ Branch 0 taken 21 times.
✓ Branch 1 taken 2416786 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✓ Branch 4 taken 49 times.
✓ Branch 5 taken 2416758 times.
|
4833593 | if ((((ulonglong)*rnd > unsigned_max) && (*rnd = (longlong)unsigned_max)) || |
| 1603 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 2416758 times.
|
2416786 | error == MY_ERRNO_ERANGE) |
| 1604 | 49 | goto out_of_range; | |
| 1605 | } else { | ||
| 1606 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 43087045 times.
|
43087065 | if (*rnd < signed_min) { |
| 1607 | 20 | *rnd = signed_min; | |
| 1608 | 20 | goto out_of_range; | |
| 1609 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 43087018 times.
|
43087045 | } else if (*rnd > signed_max) { |
| 1610 | 27 | *rnd = signed_max; | |
| 1611 | 27 | goto out_of_range; | |
| 1612 | } | ||
| 1613 | } | ||
| 1614 |
3/4✓ Branch 0 taken 45496815 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42407471 times.
✓ Branch 3 taken 3089344 times.
|
45503776 | if (current_thd->check_for_truncated_fields != 0) |
| 1615 |
1/2✓ Branch 0 taken 42378383 times.
✗ Branch 1 not taken.
|
42407471 | return check_int(cs, from, len, end, error); |
| 1616 | |||
| 1617 | 3089344 | return TYPE_OK; | |
| 1618 | |||
| 1619 | 96 | out_of_range: | |
| 1620 |
1/2✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
|
96 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); |
| 1621 | 96 | return TYPE_WARN_OUT_OF_RANGE; | |
| 1622 | } | ||
| 1623 | |||
| 1624 | /* | ||
| 1625 | This is a generic method which is executed only for | ||
| 1626 | Field_short, Field_medium, Field_long, Field_longlong and Field_tiny. | ||
| 1627 | |||
| 1628 | The other field types that come from Field_num override this method: | ||
| 1629 | Field_real (common parent for Field_decimal, Field_float, Field_double), | ||
| 1630 | Field_new_decimal, Field_year. | ||
| 1631 | */ | ||
| 1632 | 2 | type_conversion_status Field_num::store_time(MYSQL_TIME *ltime, uint8) { | |
| 1633 | 6 | longlong nr = propagate_datetime_overflow( | |
| 1634 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | current_thd, [&](int *w) { return TIME_to_ulonglong_round(*ltime, w); }); |
| 1635 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | return store(ltime->neg ? -nr : nr, false); |
| 1636 | } | ||
| 1637 | |||
| 1638 | /** | ||
| 1639 | Process decimal library return codes and issue warnings for overflow and | ||
| 1640 | truncation. | ||
| 1641 | |||
| 1642 | @param op_result decimal library return code (E_DEC_* see include/decimal.h) | ||
| 1643 | |||
| 1644 | @retval 0 No error or some other errors except overflow | ||
| 1645 | @retval 1 There was overflow | ||
| 1646 | */ | ||
| 1647 | |||
| 1648 | 2060558 | bool Field::warn_if_overflow(int op_result) { | |
| 1649 |
2/2✓ Branch 0 taken 985 times.
✓ Branch 1 taken 2059573 times.
|
2060558 | if (op_result == E_DEC_OVERFLOW) { |
| 1650 | 985 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 1651 | 985 | return true; | |
| 1652 | } | ||
| 1653 |
2/2✓ Branch 0 taken 6027 times.
✓ Branch 1 taken 2053546 times.
|
2059573 | if (op_result == E_DEC_TRUNCATED) { |
| 1654 | 6027 | set_warning(Sql_condition::SL_NOTE, WARN_DATA_TRUNCATED, 1); | |
| 1655 | /* We return 0 here as this is not a critical issue */ | ||
| 1656 | } | ||
| 1657 | 2059573 | return false; | |
| 1658 | } | ||
| 1659 | |||
| 1660 | /** | ||
| 1661 | Interpret field value as an integer but return the result as a string. | ||
| 1662 | |||
| 1663 | This is used for printing bit_fields as numbers while debugging. | ||
| 1664 | */ | ||
| 1665 | |||
| 1666 | 4 | String *Field::val_int_as_str(String *val_buffer, bool unsigned_val) const { | |
| 1667 |
4/6✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
4 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 1668 | 4 | const CHARSET_INFO *cs = &my_charset_bin; | |
| 1669 | size_t length; | ||
| 1670 | 4 | longlong value = val_int(); | |
| 1671 | |||
| 1672 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS)) return nullptr; |
| 1673 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | length = (*cs->cset->longlong10_to_str)(cs, val_buffer->ptr(), |
| 1674 | MY_INT64_NUM_DECIMAL_DIGITS, | ||
| 1675 | unsigned_val ? 10 : -10, value); | ||
| 1676 | 4 | val_buffer->length(length); | |
| 1677 | 4 | return val_buffer; | |
| 1678 | } | ||
| 1679 | |||
| 1680 | /// This is used as a table name when the table structure is not set up | ||
| 1681 | 54525005 | Field::Field(uchar *ptr_arg, uint32 length_arg, uchar *null_ptr_arg, | |
| 1682 | uchar null_bit_arg, uchar auto_flags_arg, | ||
| 1683 | 54525005 | const char *field_name_arg) | |
| 1684 | 54525005 | : ptr(ptr_arg), | |
| 1685 | 54525005 | m_hidden(dd::Column::enum_hidden_type::HT_VISIBLE), | |
| 1686 | 54525005 | m_null_ptr(null_ptr_arg), | |
| 1687 | 54525005 | m_is_tmp_nullable(false), | |
| 1688 | 54525005 | m_is_tmp_null(false), | |
| 1689 | 54525005 | m_check_for_truncated_fields_saved(CHECK_FIELD_IGNORE), | |
| 1690 | 54525005 | table(nullptr), | |
| 1691 | 54525005 | table_name(nullptr), | |
| 1692 | 54525005 | field_name(field_name_arg), | |
| 1693 | 54525026 | field_length(length_arg), | |
| 1694 | 54525026 | null_bit(null_bit_arg), | |
| 1695 | 54525026 | auto_flags(auto_flags_arg), | |
| 1696 | 54525026 | is_created_from_null_item(false), | |
| 1697 | 54525026 | zip_dict_name(null_lex_cstr), | |
| 1698 | 54525026 | zip_dict_data(null_lex_cstr), | |
| 1699 | 54525026 | m_indexed(false), | |
| 1700 | 54525026 | m_warnings_pushed(0), | |
| 1701 | 54525026 | gcol_info(nullptr), | |
| 1702 | 54525026 | stored_in_db(true), | |
| 1703 | 54525005 | m_default_val_expr(nullptr) | |
| 1704 | |||
| 1705 | { | ||
| 1706 |
2/2✓ Branch 0 taken 36825579 times.
✓ Branch 1 taken 17699433 times.
|
54525026 | if (!is_nullable()) set_flag(NOT_NULL_FLAG); |
| 1707 | 54525012 | comment.str = ""; | |
| 1708 | 54525012 | comment.length = 0; | |
| 1709 | 54525012 | m_field_index = 0; | |
| 1710 | 54525012 | } | |
| 1711 | |||
| 1712 | /** | ||
| 1713 | Check NOT NULL constraint on the field after temporary nullability is | ||
| 1714 | disabled. | ||
| 1715 | |||
| 1716 | @param mysql_errno Warning to report. | ||
| 1717 | |||
| 1718 | @return TYPE_OK if the value is Ok, or corresponding error code from | ||
| 1719 | the type_conversion_status enum. | ||
| 1720 | */ | ||
| 1721 | 285137405 | type_conversion_status Field::check_constraints(int mysql_errno) { | |
| 1722 | /* | ||
| 1723 | Ensure that Field::check_constraints() is called only when temporary | ||
| 1724 | nullability is disabled. | ||
| 1725 | */ | ||
| 1726 | |||
| 1727 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 285133037 times.
|
285137405 | assert(!is_tmp_nullable()); |
| 1728 | |||
| 1729 |
2/2✓ Branch 0 taken 172519663 times.
✓ Branch 1 taken 112610586 times.
|
285133037 | if (is_nullable()) return TYPE_OK; // If the field is nullable, we're Ok. |
| 1730 | |||
| 1731 |
2/2✓ Branch 0 taken 109662372 times.
✓ Branch 1 taken 2948214 times.
|
112610586 | if (!m_is_tmp_null) return TYPE_OK; // If the field was not NULL, we're Ok. |
| 1732 | |||
| 1733 | // The field has been set to NULL. | ||
| 1734 | |||
| 1735 | /* | ||
| 1736 | If the field is of AUTO_INCREMENT, and the next number | ||
| 1737 | has been assigned to it, we're Ok. | ||
| 1738 | */ | ||
| 1739 | |||
| 1740 |
1/2✓ Branch 0 taken 2955730 times.
✗ Branch 1 not taken.
|
2948214 | if (this == table->next_number_field) return TYPE_OK; |
| 1741 | |||
| 1742 |
2/4✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
|
71 | switch (m_check_for_truncated_fields_saved) { |
| 1743 | 81 | case CHECK_FIELD_WARN: | |
| 1744 | 81 | set_warning(Sql_condition::SL_WARNING, mysql_errno, 1); | |
| 1745 | [[fallthrough]]; | ||
| 1746 | 81 | case CHECK_FIELD_IGNORE: | |
| 1747 | 81 | return TYPE_OK; | |
| 1748 | 39 | case CHECK_FIELD_ERROR_FOR_NULL: | |
| 1749 | 39 | my_error(ER_BAD_NULL_ERROR, MYF(0), field_name); | |
| 1750 | 39 | return TYPE_ERR_NULL_CONSTRAINT_VIOLATION; | |
| 1751 | } | ||
| 1752 | |||
| 1753 | ✗ | assert(0); // impossible | |
| 1754 | my_error(ER_BAD_NULL_ERROR, MYF(0), field_name); | ||
| 1755 | return TYPE_ERR_NULL_CONSTRAINT_VIOLATION; | ||
| 1756 | } | ||
| 1757 | |||
| 1758 | /** | ||
| 1759 | Set field to value NULL. | ||
| 1760 | |||
| 1761 | @param row_offset This is the offset between the row being updated | ||
| 1762 | and table->record[0] | ||
| 1763 | */ | ||
| 1764 | 303034446 | void Field::set_null(ptrdiff_t row_offset) { | |
| 1765 |
2/2✓ Branch 0 taken 300117660 times.
✓ Branch 1 taken 2962719 times.
|
303034446 | if (is_nullable()) { |
| 1766 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 300117660 times.
|
300117660 | assert(m_null_ptr != &dummy_null_buffer); |
| 1767 | 300117660 | m_null_ptr[row_offset] |= null_bit; | |
| 1768 |
2/2✓ Branch 0 taken 2934658 times.
✓ Branch 1 taken 35765 times.
|
2962719 | } else if (is_tmp_nullable()) { |
| 1769 | 2934658 | set_tmp_null(); | |
| 1770 | } | ||
| 1771 | 303078723 | } | |
| 1772 | |||
| 1773 | /** | ||
| 1774 | Set field to value NOT NULL. | ||
| 1775 | |||
| 1776 | @param row_offset This is the offset between the row being updated | ||
| 1777 | and table->record[0] | ||
| 1778 | */ | ||
| 1779 | 1021705587 | void Field::set_notnull(ptrdiff_t row_offset) { | |
| 1780 |
2/2✓ Branch 0 taken 462450427 times.
✓ Branch 1 taken 559275546 times.
|
1021705587 | if (is_nullable()) { |
| 1781 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 462450427 times.
|
462450427 | assert(m_null_ptr != &dummy_null_buffer); |
| 1782 | 462450427 | m_null_ptr[row_offset] &= (uchar)~null_bit; | |
| 1783 |
2/2✓ Branch 0 taken 76798926 times.
✓ Branch 1 taken 438950489 times.
|
559275546 | } else if (is_tmp_nullable()) { |
| 1784 | 76798926 | reset_tmp_null(); | |
| 1785 | } | ||
| 1786 | 978199842 | } | |
| 1787 | |||
| 1788 | 51913486 | void Field::hash(ulong *nr, ulong *nr2) const { | |
| 1789 |
2/2✓ Branch 0 taken 178 times.
✓ Branch 1 taken 51913311 times.
|
51913486 | if (is_null()) { |
| 1790 | 178 | *nr ^= (*nr << 1) | 1; | |
| 1791 | } else { | ||
| 1792 |
1/2✓ Branch 0 taken 51913310 times.
✗ Branch 1 not taken.
|
51913311 | uint len = pack_length(); |
| 1793 |
1/2✓ Branch 0 taken 51913313 times.
✗ Branch 1 not taken.
|
51913310 | const CHARSET_INFO *cs = sort_charset(); |
| 1794 | 51913313 | uint64 tmp1 = *nr; | |
| 1795 | 51913313 | uint64 tmp2 = *nr2; | |
| 1796 |
1/2✓ Branch 0 taken 51913312 times.
✗ Branch 1 not taken.
|
51913313 | cs->coll->hash_sort(cs, ptr, len, &tmp1, &tmp2); |
| 1797 | |||
| 1798 | // NOTE: This truncates to 32-bit on Windows, to keep on-disk stability. | ||
| 1799 | 51913312 | *nr = static_cast<ulong>(tmp1); | |
| 1800 | 51913312 | *nr2 = static_cast<ulong>(tmp2); | |
| 1801 | } | ||
| 1802 | 51913490 | } | |
| 1803 | |||
| 1804 | 269871 | void Field::copy_data(ptrdiff_t src_record_offset) { | |
| 1805 | 269871 | memcpy(ptr, ptr + src_record_offset, pack_length()); | |
| 1806 | |||
| 1807 |
2/2✓ Branch 0 taken 90457 times.
✓ Branch 1 taken 179414 times.
|
269871 | if (is_nullable()) { |
| 1808 | // Set to NULL if the source record is NULL, otherwise set to NOT-NULL. | ||
| 1809 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 90457 times.
|
90457 | assert(m_null_ptr != &dummy_null_buffer); |
| 1810 | 90457 | m_null_ptr[0] = (m_null_ptr[0] & ~null_bit) | | |
| 1811 | 90457 | (m_null_ptr[src_record_offset] & null_bit); | |
| 1812 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 179408 times.
|
179414 | } else if (is_tmp_nullable()) |
| 1813 | 6 | m_is_tmp_null = false; | |
| 1814 | 269871 | } | |
| 1815 | |||
| 1816 | 292071148 | bool Field::send_to_protocol(Protocol *protocol) const { | |
| 1817 |
4/6✓ Branch 0 taken 292071239 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19759771 times.
✓ Branch 3 taken 272311468 times.
✓ Branch 4 taken 19759771 times.
✗ Branch 5 not taken.
|
292071148 | if (is_null()) return protocol->store_null(); |
| 1818 | char buff[MAX_FIELD_WIDTH]; | ||
| 1819 |
1/2✓ Branch 0 taken 272311492 times.
✗ Branch 1 not taken.
|
272311468 | String tmp(buff, sizeof(buff), charset()); |
| 1820 |
1/2✓ Branch 0 taken 272311515 times.
✗ Branch 1 not taken.
|
272311530 | String *res = val_str(&tmp); |
| 1821 |
2/6✓ Branch 0 taken 272311515 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 272311391 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
272311515 | return res ? protocol->store(res) : protocol->store_null(); |
| 1822 | 272311391 | } | |
| 1823 | |||
| 1824 | /** | ||
| 1825 | Checks if the current field definition and provided create field | ||
| 1826 | definition have different compression attributes. | ||
| 1827 | |||
| 1828 | @param new_field create field definition to compare with | ||
| 1829 | |||
| 1830 | @return | ||
| 1831 | true - if compression attributes are different | ||
| 1832 | false - if compression attributes are identical. | ||
| 1833 | */ | ||
| 1834 | 212143 | bool Field::has_different_compression_attributes_with( | |
| 1835 | const Create_field &new_field) const noexcept { | ||
| 1836 |
6/6✓ Branch 0 taken 212127 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 212119 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 212119 times.
✓ Branch 5 taken 24 times.
|
424270 | if (new_field.column_format() != COLUMN_FORMAT_TYPE_COMPRESSED && |
| 1837 | 212127 | column_format() != COLUMN_FORMAT_TYPE_COMPRESSED) | |
| 1838 | 212119 | return false; | |
| 1839 | |||
| 1840 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 5 times.
|
24 | if (new_field.column_format() != column_format()) return true; |
| 1841 | |||
| 1842 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
|
5 | if ((zip_dict_name.str == nullptr) && |
| 1843 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | (new_field.zip_dict_name.str == nullptr)) |
| 1844 | 3 | return false; | |
| 1845 | |||
| 1846 | 2 | return !::is_equal(&new_field.zip_dict_name, &zip_dict_name); | |
| 1847 | } | ||
| 1848 | |||
| 1849 | /** | ||
| 1850 | Check to see if field size is compatible with destination. | ||
| 1851 | |||
| 1852 | This method is used in row-based replication to verify that the | ||
| 1853 | slave's field size is less than or equal to the master's field | ||
| 1854 | size. The encoded field metadata (from the master or source) is | ||
| 1855 | decoded and compared to the size of this field (the slave or | ||
| 1856 | destination). | ||
| 1857 | |||
| 1858 | The comparison is made so that if the source data (from the master) | ||
| 1859 | is less than the target data (on the slave), -1 is returned in | ||
| 1860 | <code>*order_var</code>. This implies that a conversion is | ||
| 1861 | necessary, but that it is lossy and can result in truncation of the | ||
| 1862 | value. | ||
| 1863 | |||
| 1864 | If the source data is strictly greater than the target data, 1 is | ||
| 1865 | returned in <code>*order_var</code>. This implies that the source | ||
| 1866 | type can is contained in the target type and that a conversion is | ||
| 1867 | necessary but is non-lossy. | ||
| 1868 | |||
| 1869 | If no conversion is required to fit the source type in the target | ||
| 1870 | type, 0 is returned in <code>*order_var</code>. | ||
| 1871 | |||
| 1872 | @param field_metadata Encoded size in field metadata | ||
| 1873 | @param order_var Pointer to variable where the order | ||
| 1874 | between the source field and this field | ||
| 1875 | will be returned. | ||
| 1876 | |||
| 1877 | @return @c true if this field's size is compatible with the | ||
| 1878 | master's field size, @c false otherwise. | ||
| 1879 | */ | ||
| 1880 | 211544 | bool Field::compatible_field_size(uint field_metadata, Relay_log_info *, uint16, | |
| 1881 | int *order_var) const { | ||
| 1882 | 211544 | uint const source_size = pack_length_from_metadata(field_metadata); | |
| 1883 | 211554 | uint const destination_size = row_pack_length(); | |
| 1884 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 211546 times.
|
211550 | DBUG_PRINT("debug", ("real_type: %d, source_size: %u, destination_size: %u", |
| 1885 | real_type(), source_size, destination_size)); | ||
| 1886 | 211546 | *order_var = compare(source_size, destination_size); | |
| 1887 | 211544 | return true; | |
| 1888 | } | ||
| 1889 | |||
| 1890 | 77036 | type_conversion_status Field::store(const char *to, size_t length, | |
| 1891 | const CHARSET_INFO *cs, | ||
| 1892 | enum_check_fields check_level) { | ||
| 1893 | 77036 | THD *thd = current_thd; | |
| 1894 | 77036 | enum_check_fields old_check_level = thd->check_for_truncated_fields; | |
| 1895 | 77036 | thd->check_for_truncated_fields = check_level; | |
| 1896 | 77036 | const type_conversion_status res = store(to, length, cs); | |
| 1897 | 77036 | thd->check_for_truncated_fields = old_check_level; | |
| 1898 | 77036 | return res; | |
| 1899 | } | ||
| 1900 | |||
| 1901 | 2831180 | uchar *Field::pack(uchar *to, const uchar *from, size_t max_length) const { | |
| 1902 | 2831180 | size_t length = std::min<size_t>(pack_length(), max_length); | |
| 1903 | 2831179 | memcpy(to, from, length); | |
| 1904 | 2831179 | return to + length; | |
| 1905 | } | ||
| 1906 | |||
| 1907 | /** | ||
| 1908 | Unpack a field from row data. | ||
| 1909 | |||
| 1910 | This method is used to unpack a field from a master whose size of | ||
| 1911 | the field is less than that of the slave. | ||
| 1912 | |||
| 1913 | The <code>param_data</code> parameter is a two-byte integer (stored | ||
| 1914 | in the least significant 16 bits of the unsigned integer) usually | ||
| 1915 | consisting of two parts: the real type in the most significant byte | ||
| 1916 | and a original pack length in the least significant byte. | ||
| 1917 | |||
| 1918 | The exact layout of the <code>param_data</code> field is given by | ||
| 1919 | the <code>Table_map_log_event::save_field_metadata()</code>. | ||
| 1920 | |||
| 1921 | This is the default method for unpacking a field. It just copies | ||
| 1922 | the memory block in byte order (of original pack length bytes or | ||
| 1923 | length of field, whichever is smaller). | ||
| 1924 | |||
| 1925 | @param to Destination of the data | ||
| 1926 | @param from Source of the data | ||
| 1927 | @param param_data Real type and original pack length of the field | ||
| 1928 | data | ||
| 1929 | |||
| 1930 | @return New pointer into memory based on from + length of the data | ||
| 1931 | */ | ||
| 1932 | 463493 | const uchar *Field::unpack(uchar *to, const uchar *from, uint param_data) { | |
| 1933 | 463493 | uint length = pack_length(); | |
| 1934 | 463493 | int from_type = 0; | |
| 1935 | /* | ||
| 1936 | If from length is > 255, it has encoded data in the upper bits. Need | ||
| 1937 | to mask it out. | ||
| 1938 | */ | ||
| 1939 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 463493 times.
|
463493 | if (param_data > 255) { |
| 1940 | ✗ | from_type = (param_data & 0xff00) >> 8U; // real_type. | |
| 1941 | ✗ | param_data = param_data & 0x00ff; // length. | |
| 1942 | } | ||
| 1943 | |||
| 1944 |
5/6✓ Branch 0 taken 14877 times.
✓ Branch 1 taken 448616 times.
✓ Branch 2 taken 1992 times.
✓ Branch 3 taken 12885 times.
✓ Branch 4 taken 463493 times.
✗ Branch 5 not taken.
|
465485 | if ((param_data == 0) || (length == param_data) || |
| 1945 |
1/2✓ Branch 0 taken 1992 times.
✗ Branch 1 not taken.
|
1992 | (from_type != real_type())) { |
| 1946 | 463493 | memcpy(to, from, length); | |
| 1947 | 463493 | return from + length; | |
| 1948 | } | ||
| 1949 | |||
| 1950 | ✗ | uint len = (param_data && (param_data < length)) ? param_data : length; | |
| 1951 | |||
| 1952 | ✗ | memcpy(to, from, param_data > length ? length : len); | |
| 1953 | ✗ | return from + len; | |
| 1954 | } | ||
| 1955 | |||
| 1956 | /** | ||
| 1957 | Appends the UNSIGNED and ZEROFILL attributes to a String if a Field_num has | ||
| 1958 | these attributes. | ||
| 1959 | |||
| 1960 | @param field the field with the attributes to append | ||
| 1961 | @param[in,out] res the String to append to | ||
| 1962 | */ | ||
| 1963 | 5183927 | static void append_zerofill_and_unsigned(const Field_num *field, String *res) { | |
| 1964 |
2/2✓ Branch 0 taken 3271225 times.
✓ Branch 1 taken 1912696 times.
|
5183927 | if (field->is_unsigned()) res->append(STRING_WITH_LEN(" unsigned")); |
| 1965 |
2/2✓ Branch 0 taken 4846 times.
✓ Branch 1 taken 5179075 times.
|
5183921 | if (field->zerofill) res->append(STRING_WITH_LEN(" zerofill")); |
| 1966 | 5183921 | } | |
| 1967 | |||
| 1968 | /// Writes an integer type specification to a string. | ||
| 1969 | 4799235 | static void integer_sql_type(const Field_num *field, const char *type_name, | |
| 1970 | String *res) { | ||
| 1971 | 4799235 | res->length(0); | |
| 1972 |
1/2✓ Branch 0 taken 4799289 times.
✗ Branch 1 not taken.
|
4799308 | res->append(type_name); |
| 1973 |
2/2✓ Branch 0 taken 1092 times.
✓ Branch 1 taken 4798197 times.
|
4799289 | if (field->zerofill) res->append_parenthesized(field->field_length); |
| 1974 | 4799289 | append_zerofill_and_unsigned(field, res); | |
| 1975 | 4799252 | } | |
| 1976 | |||
| 1977 | 6742859 | void Field::make_send_field(Send_field *field) const { | |
| 1978 |
2/2✓ Branch 0 taken 1836582 times.
✓ Branch 1 taken 4906277 times.
|
6742859 | field->db_name = orig_db_name ? orig_db_name : table->s->db.str; |
| 1979 |
2/2✓ Branch 0 taken 1836584 times.
✓ Branch 1 taken 4906275 times.
|
6742859 | field->org_table_name = orig_table_name ? orig_table_name : ""; |
| 1980 | 6742859 | field->table_name = table->alias; | |
| 1981 | 6742859 | field->org_col_name = field_name; | |
| 1982 | 6742859 | field->col_name = field_name; | |
| 1983 | 6742859 | field->charsetnr = charset()->number; | |
| 1984 | 6742864 | field->length = field_length; | |
| 1985 | 6742864 | field->type = type(); | |
| 1986 | 6742864 | field->flags = all_flags(); | |
| 1987 |
2/2✓ Branch 0 taken 12333 times.
✓ Branch 1 taken 6730531 times.
|
6742865 | if (table->is_nullable()) field->flags &= ~NOT_NULL_FLAG; |
| 1988 | 6742864 | field->decimals = decimals(); | |
| 1989 | 6742862 | field->field = false; | |
| 1990 | 6742862 | } | |
| 1991 | |||
| 1992 | /** | ||
| 1993 | Conversion from decimal to longlong. Checks overflow and returns | ||
| 1994 | correct value (min/max) in case of overflow. | ||
| 1995 | |||
| 1996 | @param val value to be converted | ||
| 1997 | @param unsigned_flag type of integer to which we convert val | ||
| 1998 | @param has_overflow true if there is overflow | ||
| 1999 | |||
| 2000 | @return | ||
| 2001 | value converted from val | ||
| 2002 | */ | ||
| 2003 | 432603 | longlong Field::convert_decimal2longlong(const my_decimal *val, | |
| 2004 | bool unsigned_flag, | ||
| 2005 | bool *has_overflow) { | ||
| 2006 |
6/6✓ Branch 0 taken 1268 times.
✓ Branch 1 taken 431335 times.
✓ Branch 2 taken 124 times.
✓ Branch 3 taken 1144 times.
✓ Branch 4 taken 124 times.
✓ Branch 5 taken 432479 times.
|
432603 | if (unsigned_flag && val->sign()) { |
| 2007 | // Converting a signed decimal to unsigned int | ||
| 2008 |
1/2✓ Branch 0 taken 124 times.
✗ Branch 1 not taken.
|
124 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); |
| 2009 | 124 | *has_overflow = true; | |
| 2010 | 124 | return 0; | |
| 2011 | } | ||
| 2012 | |||
| 2013 | longlong val_ll; | ||
| 2014 | int conversion_error = | ||
| 2015 |
1/2✓ Branch 0 taken 432479 times.
✗ Branch 1 not taken.
|
432479 | my_decimal2int(E_DEC_ERROR & ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED, val, |
| 2016 | unsigned_flag, &val_ll); | ||
| 2017 | |||
| 2018 |
3/4✓ Branch 0 taken 432479 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 337 times.
✓ Branch 3 taken 432142 times.
|
432479 | if (warn_if_overflow(conversion_error)) { |
| 2019 | 337 | *has_overflow = true; | |
| 2020 |
2/2✓ Branch 0 taken 116 times.
✓ Branch 1 taken 221 times.
|
337 | if (unsigned_flag) return ULLONG_MAX; |
| 2021 | |||
| 2022 |
2/2✓ Branch 0 taken 158 times.
✓ Branch 1 taken 63 times.
|
221 | return (val->sign() ? LLONG_MIN : LLONG_MAX); |
| 2023 | } | ||
| 2024 | |||
| 2025 | 432142 | return val_ll; | |
| 2026 | } | ||
| 2027 | |||
| 2028 | /** | ||
| 2029 | Storing decimal in integer fields. | ||
| 2030 | |||
| 2031 | @param val value for storing | ||
| 2032 | |||
| 2033 | @note | ||
| 2034 | This method is used by all integer fields, real/decimal redefine it | ||
| 2035 | |||
| 2036 | @retval TYPE_OK Storage of value went fine without warnings or errors | ||
| 2037 | @retval !TYPE_OK Warning/error as indicated by type_conversion_status enum | ||
| 2038 | value | ||
| 2039 | */ | ||
| 2040 | 432603 | type_conversion_status Field_num::store_decimal(const my_decimal *val) { | |
| 2041 |
4/6✓ Branch 0 taken 432603 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 432560 times.
✓ Branch 3 taken 43 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 432560 times.
|
432603 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 2042 | 432603 | bool has_overflow = false; | |
| 2043 |
1/2✓ Branch 0 taken 432603 times.
✗ Branch 1 not taken.
|
432603 | longlong i = convert_decimal2longlong(val, is_unsigned(), &has_overflow); |
| 2044 |
1/2✓ Branch 0 taken 432603 times.
✗ Branch 1 not taken.
|
432603 | const type_conversion_status res = store(i, is_unsigned()); |
| 2045 |
2/2✓ Branch 0 taken 461 times.
✓ Branch 1 taken 432142 times.
|
432603 | return has_overflow ? TYPE_WARN_OUT_OF_RANGE : res; |
| 2046 | } | ||
| 2047 | |||
| 2048 | /** | ||
| 2049 | Return decimal value of integer field. | ||
| 2050 | |||
| 2051 | @param decimal_value buffer for storing decimal value | ||
| 2052 | |||
| 2053 | @note | ||
| 2054 | This method is used by all integer fields, real/decimal redefine it. | ||
| 2055 | All longlong values fit in our decimal buffer which cal store 8*9=72 | ||
| 2056 | digits of integer number | ||
| 2057 | |||
| 2058 | @return | ||
| 2059 | pointer to decimal buffer with value of field | ||
| 2060 | */ | ||
| 2061 | |||
| 2062 | 36118547 | my_decimal *Field_num::val_decimal(my_decimal *decimal_value) const { | |
| 2063 |
4/6✓ Branch 0 taken 36118547 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36117537 times.
✓ Branch 3 taken 1010 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 36117537 times.
|
36118547 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 2064 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36118547 times.
|
36118547 | assert(result_type() == INT_RESULT); |
| 2065 | 36118547 | longlong nr = val_int(); | |
| 2066 | 36118547 | int2my_decimal(E_DEC_FATAL_ERROR, nr, is_unsigned(), decimal_value); | |
| 2067 | 36118547 | return decimal_value; | |
| 2068 | } | ||
| 2069 | |||
| 2070 | 124 | bool Field_num::get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const { | |
| 2071 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 124 times.
|
124 | assert(result_type() == INT_RESULT); |
| 2072 | 124 | return my_longlong_to_datetime_with_warn(val_int(), ltime, fuzzydate); | |
| 2073 | } | ||
| 2074 | |||
| 2075 | 56 | bool Field_num::get_time(MYSQL_TIME *ltime) const { | |
| 2076 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | assert(result_type() == INT_RESULT); |
| 2077 | 56 | return my_longlong_to_time_with_warn(val_int(), ltime); | |
| 2078 | } | ||
| 2079 | |||
| 2080 | 28030978 | Field_str::Field_str(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, | |
| 2081 | uchar null_bit_arg, uchar auto_flags_arg, | ||
| 2082 | const char *field_name_arg, | ||
| 2083 | 28030978 | const CHARSET_INFO *charset_arg) | |
| 2084 | : Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg, | ||
| 2085 | 28030978 | field_name_arg) { | |
| 2086 | 28030979 | field_charset = charset_arg; | |
| 2087 |
2/2✓ Branch 0 taken 13798471 times.
✓ Branch 1 taken 14232508 times.
|
28030979 | if (charset_arg->state & MY_CS_BINSORT) set_flag(BINARY_FLAG); |
| 2088 | 28030979 | field_derivation = DERIVATION_IMPLICIT; | |
| 2089 |
1/2✓ Branch 0 taken 28030978 times.
✗ Branch 1 not taken.
|
28030979 | char_length_cache = char_length(); |
| 2090 | 28030978 | } | |
| 2091 | |||
| 2092 | 4780977 | void Field_str::make_send_field(Send_field *field) const { | |
| 2093 | 4780977 | Field::make_send_field(field); | |
| 2094 | 4780980 | field->decimals = 0; | |
| 2095 | 4780980 | } | |
| 2096 | |||
| 2097 | /** | ||
| 2098 | Decimal representation of Field_str. | ||
| 2099 | |||
| 2100 | @param d value for storing | ||
| 2101 | |||
| 2102 | @note | ||
| 2103 | Field_str is the base class for fields implementing | ||
| 2104 | [VAR]CHAR, VAR[BINARY], BLOB/TEXT, GEOMETRY, JSON. | ||
| 2105 | String value should be converted to floating point value according | ||
| 2106 | our rules, so we use double to store value of decimal in string. | ||
| 2107 | |||
| 2108 | @todo | ||
| 2109 | use decimal2string? | ||
| 2110 | |||
| 2111 | @retval | ||
| 2112 | 0 OK | ||
| 2113 | @retval | ||
| 2114 | !=0 error | ||
| 2115 | */ | ||
| 2116 | |||
| 2117 | 1 | type_conversion_status Field_str::store_decimal(const my_decimal *d) { | |
| 2118 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 2119 | double val; | ||
| 2120 | /* TODO: use decimal2string? */ | ||
| 2121 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | int err = my_decimal2double(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, d, &val); |
| 2122 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | warn_if_overflow(err); |
| 2123 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | const type_conversion_status res = store(val); |
| 2124 | |||
| 2125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | return (err != E_DEC_OK) ? decimal_err_to_type_conv_status(err) : res; |
| 2126 | } | ||
| 2127 | |||
| 2128 | 534 | bool Field::get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const { | |
| 2129 | char buff[MAX_DATE_STRING_REP_LENGTH]; | ||
| 2130 | 534 | String tmp(buff, sizeof(buff), &my_charset_bin), *res; | |
| 2131 |
2/4✓ Branch 0 taken 534 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 534 times.
✗ Branch 3 not taken.
|
1068 | return !(res = val_str(&tmp)) || |
| 2132 |
3/4✓ Branch 0 taken 534 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 219 times.
✓ Branch 3 taken 315 times.
|
1068 | str_to_datetime_with_warn(res, ltime, fuzzydate); |
| 2133 | 534 | } | |
| 2134 | |||
| 2135 | 144 | bool Field::get_time(MYSQL_TIME *ltime) const { | |
| 2136 | char buff[MAX_DATE_STRING_REP_LENGTH]; | ||
| 2137 | 144 | String tmp(buff, sizeof(buff), &my_charset_bin), *res; | |
| 2138 |
5/8✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 144 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 82 times.
✓ Branch 7 taken 62 times.
|
288 | return !(res = val_str(&tmp)) || str_to_time_with_warn(res, ltime); |
| 2139 | 144 | } | |
| 2140 | |||
| 2141 | 164 | bool Field::get_timestamp(my_timeval *tm, int *warnings) const { | |
| 2142 | MYSQL_TIME ltime; | ||
| 2143 |
2/4✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 164 times.
|
164 | assert(!is_null()); |
| 2144 |
3/4✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 161 times.
✓ Branch 3 taken 3 times.
|
325 | return get_date(<ime, TIME_FUZZY_DATE) || |
| 2145 |
4/6✓ Branch 0 taken 161 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 161 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 145 times.
|
325 | datetime_to_timeval(<ime, *current_thd->time_zone(), tm, warnings); |
| 2146 | } | ||
| 2147 | |||
| 2148 | /** | ||
| 2149 | This is called when storing a date in a string. | ||
| 2150 | |||
| 2151 | @note | ||
| 2152 | Needs to be changed if/when we want to support different time formats. | ||
| 2153 | */ | ||
| 2154 | |||
| 2155 | 225 | type_conversion_status Field::store_time(MYSQL_TIME *ltime, uint8 dec_arg) { | |
| 2156 |
3/6✓ Branch 0 taken 225 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 225 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 225 times.
|
225 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 2157 | char buff[MAX_DATE_STRING_REP_LENGTH]; | ||
| 2158 | 450 | uint length = my_TIME_to_str(*ltime, buff, | |
| 2159 |
1/2✓ Branch 0 taken 225 times.
✗ Branch 1 not taken.
|
225 | std::min(dec_arg, uint8{DATETIME_MAX_DECIMALS})); |
| 2160 | /* Avoid conversion when field character set is ASCII compatible */ | ||
| 2161 |
1/2✓ Branch 0 taken 225 times.
✗ Branch 1 not taken.
|
225 | return store( |
| 2162 | buff, length, | ||
| 2163 |
4/6✓ Branch 0 taken 225 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 211 times.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 211 times.
✗ Branch 5 not taken.
|
675 | (charset()->state & MY_CS_NONASCII) ? &my_charset_latin1 : charset()); |
| 2164 | } | ||
| 2165 | |||
| 2166 | 11837848 | bool Field::optimize_range(uint idx, uint part) const { | |
| 2167 | 11837848 | return table->file->index_flags(idx, part, true) & HA_READ_RANGE; | |
| 2168 | } | ||
| 2169 | |||
| 2170 | 6136654 | Field *Field::new_field(MEM_ROOT *root, TABLE *new_table) const { | |
| 2171 | 6136654 | Field *tmp = clone(root); | |
| 2172 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6136646 times.
|
6136646 | if (tmp == nullptr) return nullptr; |
| 2173 | |||
| 2174 |
5/6✓ Branch 0 taken 6136656 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 784149 times.
✓ Branch 3 taken 5352511 times.
✓ Branch 4 taken 784149 times.
✓ Branch 5 taken 5352501 times.
|
6136646 | if (tmp->table && tmp->table->is_nullable()) tmp->clear_flag(NOT_NULL_FLAG); |
| 2175 | 6136651 | tmp->table = new_table; | |
| 2176 | 6136651 | tmp->key_start.init(0); | |
| 2177 | 6136667 | tmp->part_of_key.init(0); | |
| 2178 | 6136673 | tmp->part_of_prefixkey.init(0); | |
| 2179 | 6136672 | tmp->part_of_sortkey.init(0); | |
| 2180 | 6136669 | tmp->m_indexed = false; | |
| 2181 | // Set original db & table name, unless already copied from the old field | ||
| 2182 |
4/4✓ Branch 0 taken 5969359 times.
✓ Branch 1 taken 167310 times.
✓ Branch 2 taken 5903163 times.
✓ Branch 3 taken 66196 times.
|
6136669 | if (tmp->orig_db_name == nullptr && table->pos_in_table_list != nullptr) |
| 2183 | 5903163 | tmp->orig_db_name = table->pos_in_table_list->db; | |
| 2184 |
4/4✓ Branch 0 taken 5969362 times.
✓ Branch 1 taken 167307 times.
✓ Branch 2 taken 5903168 times.
✓ Branch 3 taken 66194 times.
|
6136669 | if (tmp->orig_table_name == nullptr && table->pos_in_table_list != nullptr) |
| 2185 | 5903168 | tmp->orig_table_name = table->pos_in_table_list->table_name; | |
| 2186 | /* | ||
| 2187 | todo: We should never alter auto_flags after an object is constructed, | ||
| 2188 | and the member should be made const. But a lot of code depends upon this | ||
| 2189 | hack, and some flags are completely unrelated so we can never be quite | ||
| 2190 | sure which parts of the server will break. | ||
| 2191 | */ | ||
| 2192 | 6136669 | tmp->auto_flags = Field::NONE; | |
| 2193 | /* COMPRESSED column format flag must not be cleared here */ | ||
| 2194 | const bool has_compressed_flag = | ||
| 2195 | 6136669 | (tmp->column_format() == COLUMN_FORMAT_TYPE_COMPRESSED); | |
| 2196 | 6136663 | tmp->flags &= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | ZEROFILL_FLAG | | |
| 2197 | BINARY_FLAG | ENUM_FLAG | SET_FLAG | NOT_SECONDARY_FLAG); | ||
| 2198 |
2/2✓ Branch 0 taken 204 times.
✓ Branch 1 taken 6136459 times.
|
6136663 | if (has_compressed_flag) |
| 2199 | 204 | tmp->set_column_format(COLUMN_FORMAT_TYPE_COMPRESSED); | |
| 2200 | 6136664 | return tmp; | |
| 2201 | } | ||
| 2202 | |||
| 2203 | 2784504 | Field *Field::new_key_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr, | |
| 2204 | uchar *new_null_ptr, uint new_null_bit) const { | ||
| 2205 | 2784504 | Field *tmp = new_field(root, new_table); | |
| 2206 |
1/2✓ Branch 0 taken 2784529 times.
✗ Branch 1 not taken.
|
2784519 | if (tmp != nullptr) { |
| 2207 | 2784529 | tmp->ptr = new_ptr; | |
| 2208 | 2784529 | tmp->m_null_ptr = new_null_ptr; | |
| 2209 | 2784529 | tmp->null_bit = new_null_bit; | |
| 2210 | } | ||
| 2211 | 2784519 | return tmp; | |
| 2212 | } | ||
| 2213 | |||
| 2214 | 4555406 | void Field::evaluate_insert_default_function() { | |
| 2215 |
2/2✓ Branch 0 taken 4554581 times.
✓ Branch 1 taken 825 times.
|
4555406 | if (has_insert_default_datetime_value_expression()) |
| 2216 | 4554581 | Item_func_now_local::store_in(this); | |
| 2217 | // evaluate and store the values generated by default expression | ||
| 2218 |
2/2✓ Branch 0 taken 822 times.
✓ Branch 1 taken 3 times.
|
825 | else if (has_insert_default_general_value_expression()) |
| 2219 | 822 | m_default_val_expr->expr_item->save_in_field(this, false); | |
| 2220 | 4555406 | } | |
| 2221 | |||
| 2222 | 43942 | void Field::evaluate_update_default_function() { | |
| 2223 |
2/2✓ Branch 0 taken 43939 times.
✓ Branch 1 taken 3 times.
|
43942 | if (has_update_default_datetime_value_expression()) |
| 2224 | 43939 | Item_func_now_local::store_in(this); | |
| 2225 | 43942 | } | |
| 2226 | |||
| 2227 | /**************************************************************************** | ||
| 2228 | Field_null, a field that always return NULL | ||
| 2229 | ****************************************************************************/ | ||
| 2230 | |||
| 2231 | ✗ | void Field_null::sql_type(String &res) const { | |
| 2232 | ✗ | res.set_ascii(STRING_WITH_LEN("null")); | |
| 2233 | } | ||
| 2234 | |||
| 2235 | /**************************************************************************** | ||
| 2236 | Functions for the Field_decimal class | ||
| 2237 | This is an number stored as a pre-space (or pre-zero) string | ||
| 2238 | ****************************************************************************/ | ||
| 2239 | |||
| 2240 | ✗ | void Field_decimal::overflow(bool negative) { | |
| 2241 | ✗ | uint len = field_length; | |
| 2242 | ✗ | uchar *to = ptr, filler = '9'; | |
| 2243 | |||
| 2244 | ✗ | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 2245 | ✗ | if (negative) { | |
| 2246 | ✗ | if (!is_unsigned()) { | |
| 2247 | /* Put - sign as a first digit so we'll have -999..999 or 999..999 */ | ||
| 2248 | ✗ | *to++ = '-'; | |
| 2249 | ✗ | len--; | |
| 2250 | } else { | ||
| 2251 | ✗ | filler = '0'; // Fill up with 0 | |
| 2252 | ✗ | if (!zerofill) { | |
| 2253 | /* | ||
| 2254 | Handle unsigned integer without zerofill, in which case | ||
| 2255 | the number should be of format ' 0' or ' 0.000' | ||
| 2256 | */ | ||
| 2257 | ✗ | uint whole_part = field_length - (dec ? dec + 2 : 1); | |
| 2258 | // Fill with spaces up to the first digit | ||
| 2259 | ✗ | memset(to, ' ', whole_part); | |
| 2260 | ✗ | to += whole_part; | |
| 2261 | ✗ | len -= whole_part; | |
| 2262 | // The main code will also handle the 0 before the decimal point | ||
| 2263 | } | ||
| 2264 | } | ||
| 2265 | } | ||
| 2266 | ✗ | memset(to, filler, len); | |
| 2267 | ✗ | if (dec) ptr[field_length - dec - 1] = '.'; | |
| 2268 | ✗ | return; | |
| 2269 | } | ||
| 2270 | |||
| 2271 | ✗ | type_conversion_status Field_decimal::store(const char *from_arg, size_t len, | |
| 2272 | const CHARSET_INFO *cs) { | ||
| 2273 | ✗ | ASSERT_COLUMN_MARKED_FOR_WRITE; | |
| 2274 | char buff[STRING_BUFFER_USUAL_SIZE]; | ||
| 2275 | ✗ | String tmp(buff, sizeof(buff), &my_charset_bin); | |
| 2276 | ✗ | const uchar *from = pointer_cast<const uchar *>(from_arg); | |
| 2277 | |||
| 2278 | ✗ | THD *thd = current_thd; | |
| 2279 | |||
| 2280 | /* Convert character set if the old one is multi uchar */ | ||
| 2281 | ✗ | if (cs->mbmaxlen > 1) { | |
| 2282 | uint dummy_errors; | ||
| 2283 | ✗ | tmp.copy(from_arg, len, cs, &my_charset_bin, &dummy_errors); | |
| 2284 | ✗ | from = (uchar *)tmp.ptr(); | |
| 2285 | ✗ | len = tmp.length(); | |
| 2286 | } | ||
| 2287 | |||
| 2288 | ✗ | const uchar *end = from + len; | |
| 2289 | /* The pointer where the field value starts (i.e., "where to write") */ | ||
| 2290 | ✗ | uchar *to = ptr; | |
| 2291 | uint tmp_dec, tmp_uint; | ||
| 2292 | /* | ||
| 2293 | The sign of the number : will be 0 (means positive but sign not | ||
| 2294 | specified), '+' or '-' | ||
| 2295 | */ | ||
| 2296 | ✗ | uchar sign_char = 0; | |
| 2297 | /* The pointers where prezeros start and stop */ | ||
| 2298 | const uchar *pre_zeros_from, *pre_zeros_end; | ||
| 2299 | /* The pointers where digits at the left of '.' start and stop */ | ||
| 2300 | const uchar *int_digits_from, *int_digits_end; | ||
| 2301 | /* The pointers where digits at the right of '.' start and stop */ | ||
| 2302 | const uchar *frac_digits_from, *frac_digits_end; | ||
| 2303 | /* The sign of the exponent : will be 0 (means no exponent), '+' or '-' */ | ||
| 2304 | ✗ | char expo_sign_char = 0; | |
| 2305 | ✗ | uint exponent = 0; // value of the exponent | |
| 2306 | /* | ||
| 2307 | Pointers used when digits move from the left of the '.' to the | ||
| 2308 | right of the '.' (explained below) | ||
| 2309 | */ | ||
| 2310 | ✗ | const uchar *int_digits_tail_from = nullptr; | |
| 2311 | /* Number of 0 that need to be added at the left of the '.' (1E3: 3 zeros) */ | ||
| 2312 | ✗ | uint int_digits_added_zeros = 0; | |
| 2313 | /* | ||
| 2314 | Pointer used when digits move from the right of the '.' to the left | ||
| 2315 | of the '.' | ||
| 2316 | */ | ||
| 2317 | ✗ | const uchar *frac_digits_head_end = nullptr; | |
| 2318 | /* Number of 0 that need to be added at the right of the '.' (for 1E-3) */ | ||
| 2319 | ✗ | uint frac_digits_added_zeros = 0; | |
| 2320 | uchar *pos, *tmp_left_pos, *tmp_right_pos; | ||
| 2321 | /* Pointers that are used as limits (begin and end of the field buffer) */ | ||
| 2322 | uchar *left_wall, *right_wall; | ||
| 2323 | uchar tmp_char; | ||
| 2324 | /* | ||
| 2325 | To remember if thd->num_truncated_fields has already | ||
| 2326 | been incremented, to do that only once | ||
| 2327 | */ | ||
| 2328 | ✗ | bool has_incremented_num_truncated_fields = false; | |
| 2329 | |||
| 2330 | /* | ||
| 2331 | There are three steps in this function : | ||
| 2332 | - parse the input string | ||
| 2333 | - modify the position of digits around the decimal dot '.' | ||
| 2334 | according to the exponent value (if specified) | ||
| 2335 | - write the formatted number | ||
| 2336 | */ | ||
| 2337 | |||
| 2338 | ✗ | if ((tmp_dec = dec)) tmp_dec++; | |
| 2339 | |||
| 2340 | /* skip pre-space */ | ||
| 2341 | ✗ | while (from != end && my_isspace(&my_charset_bin, *from)) from++; | |
| 2342 | ✗ | if (from == end) { | |
| 2343 | ✗ | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); | |
| 2344 | ✗ | has_incremented_num_truncated_fields = true; | |
| 2345 | ✗ | } else if (*from == '+' || *from == '-') // Found some sign ? | |
| 2346 | { | ||
| 2347 | ✗ | sign_char = *from++; | |
| 2348 | /* | ||
| 2349 | We allow "+" for unsigned decimal unless defined different | ||
| 2350 | Both options allowed as one may wish not to have "+" for unsigned numbers | ||
| 2351 | because of data processing issues | ||
| 2352 | */ | ||
| 2353 | ✗ | if (is_unsigned()) { | |
| 2354 | ✗ | if (sign_char == '-') { | |
| 2355 | ✗ | Field_decimal::overflow(true); | |
| 2356 | ✗ | return TYPE_WARN_OUT_OF_RANGE; | |
| 2357 | } | ||
| 2358 | } | ||
| 2359 | } | ||
| 2360 | |||
| 2361 | ✗ | pre_zeros_from = from; | |
| 2362 | ✗ | for (; from != end && *from == '0'; from++) | |
| 2363 | ; // Read prezeros | ||
| 2364 | ✗ | pre_zeros_end = int_digits_from = from; | |
| 2365 | /* Read non zero digits at the left of '.'*/ | ||
| 2366 | ✗ | for (; from != end && my_isdigit(&my_charset_bin, *from); from++) | |
| 2367 | ; | ||
| 2368 | ✗ | int_digits_end = from; | |
| 2369 | ✗ | if (from != end && *from == '.') // Some '.' ? | |
| 2370 | ✗ | from++; | |
| 2371 | ✗ | frac_digits_from = from; | |
| 2372 | /* Read digits at the right of '.' */ | ||
| 2373 | ✗ | for (; from != end && my_isdigit(&my_charset_bin, *from); from++) | |
| 2374 | ; | ||
| 2375 | ✗ | frac_digits_end = from; | |
| 2376 | // Some exponentiation symbol ? | ||
| 2377 | ✗ | if (from != end && (*from == 'e' || *from == 'E')) { | |
| 2378 | ✗ | from++; | |
| 2379 | ✗ | if (from != end && (*from == '+' || *from == '-')) // Some exponent sign ? | |
| 2380 | ✗ | expo_sign_char = *from++; | |
| 2381 | else | ||
| 2382 | ✗ | expo_sign_char = '+'; | |
| 2383 | /* | ||
| 2384 | Read digits of the exponent and compute its value. We must care about | ||
| 2385 | 'exponent' overflow, because as unsigned arithmetic is "modulo", big | ||
| 2386 | exponents will become small (e.g. 1e4294967296 will become 1e0, and the | ||
| 2387 | field will finally contain 1 instead of its max possible value). | ||
| 2388 | */ | ||
| 2389 | ✗ | for (; from != end && my_isdigit(&my_charset_bin, *from); from++) { | |
| 2390 | ✗ | exponent = 10 * exponent + (*from - '0'); | |
| 2391 | ✗ | if (exponent > MAX_EXPONENT) break; | |
| 2392 | } | ||
| 2393 | } | ||
| 2394 | |||
| 2395 | /* | ||
| 2396 | We only have to generate warnings if check_for_truncated_fields is set. | ||
| 2397 | This is to avoid extra checks of the number when they are not needed. | ||
| 2398 | Even if this flag is not set, it's OK to increment warnings, if | ||
| 2399 | it makes the code easier to read. | ||
| 2400 | */ | ||
| 2401 | |||
| 2402 | ✗ | if (thd->check_for_truncated_fields) { | |
| 2403 | // Skip end spaces | ||
| 2404 | ✗ | for (; from != end && my_isspace(&my_charset_bin, *from); from++) | |
| 2405 | ; | ||
| 2406 | ✗ | if (from != end) // If still something left, warn | |
| 2407 | { | ||
| 2408 | ✗ | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); | |
| 2409 | ✗ | has_incremented_num_truncated_fields = true; | |
| 2410 | } | ||
| 2411 | } | ||
| 2412 | |||
| 2413 | /* | ||
| 2414 | Now "move" digits around the decimal dot according to the exponent value, | ||
| 2415 | and add necessary zeros. | ||
| 2416 | Examples : | ||
| 2417 | - 1E+3 : needs 3 more zeros at the left of '.' (int_digits_added_zeros=3) | ||
| 2418 | - 1E-3 : '1' moves at the right of '.', and 2 more zeros are needed | ||
| 2419 | between '.' and '1' | ||
| 2420 | - 1234.5E-3 : '234' moves at the right of '.' | ||
| 2421 | These moves are implemented with pointers which point at the begin | ||
| 2422 | and end of each moved segment. Examples : | ||
| 2423 | - 1234.5E-3 : before the code below is executed, the int_digits part is | ||
| 2424 | from '1' to '4' and the frac_digits part from '5' to '5'. After the code | ||
| 2425 | below, the int_digits part is from '1' to '1', the frac_digits_head | ||
| 2426 | part is from '2' to '4', and the frac_digits part from '5' to '5'. | ||
| 2427 | - 1234.5E3 : before the code below is executed, the int_digits part is | ||
| 2428 | from '1' to '4' and the frac_digits part from '5' to '5'. After the code | ||
| 2429 | below, the int_digits part is from '1' to '4', the int_digits_tail | ||
| 2430 | part is from '5' to '5', the frac_digits part is empty, and | ||
| 2431 | int_digits_added_zeros=2 (to make 1234500). | ||
| 2432 | */ | ||
| 2433 | |||
| 2434 | /* | ||
| 2435 | Below tmp_uint cannot overflow with small enough MAX_EXPONENT setting, | ||
| 2436 | as int_digits_added_zeros<=exponent<4G and | ||
| 2437 | (int_digits_end-int_digits_from)<=max_allowed_packet<=2G and | ||
| 2438 | (frac_digits_from-int_digits_tail_from)<=max_allowed_packet<=2G | ||
| 2439 | */ | ||
| 2440 | |||
| 2441 | ✗ | if (!expo_sign_char) | |
| 2442 | ✗ | tmp_uint = tmp_dec + (uint)(int_digits_end - int_digits_from); | |
| 2443 | ✗ | else if (expo_sign_char == '-') { | |
| 2444 | ✗ | tmp_uint = min(exponent, (uint)(int_digits_end - int_digits_from)); | |
| 2445 | ✗ | frac_digits_added_zeros = exponent - tmp_uint; | |
| 2446 | ✗ | int_digits_end -= tmp_uint; | |
| 2447 | ✗ | frac_digits_head_end = int_digits_end + tmp_uint; | |
| 2448 | ✗ | tmp_uint = tmp_dec + (uint)(int_digits_end - int_digits_from); | |
| 2449 | } else // (expo_sign_char=='+') | ||
| 2450 | { | ||
| 2451 | ✗ | tmp_uint = min(exponent, (uint)(frac_digits_end - frac_digits_from)); | |
| 2452 | ✗ | int_digits_added_zeros = exponent - tmp_uint; | |
| 2453 | ✗ | int_digits_tail_from = frac_digits_from; | |
| 2454 | ✗ | frac_digits_from = frac_digits_from + tmp_uint; | |
| 2455 | /* | ||
| 2456 | We "eat" the heading zeros of the | ||
| 2457 | int_digits.int_digits_tail.int_digits_added_zeros concatenation | ||
| 2458 | (for example 0.003e3 must become 3 and not 0003) | ||
| 2459 | */ | ||
| 2460 | ✗ | if (int_digits_from == int_digits_end) { | |
| 2461 | /* | ||
| 2462 | There was nothing in the int_digits part, so continue | ||
| 2463 | eating int_digits_tail zeros | ||
| 2464 | */ | ||
| 2465 | ✗ | for (; int_digits_tail_from != frac_digits_from && | |
| 2466 | ✗ | *int_digits_tail_from == '0'; | |
| 2467 | int_digits_tail_from++) | ||
| 2468 | ; | ||
| 2469 | ✗ | if (int_digits_tail_from == frac_digits_from) { | |
| 2470 | // there were only zeros in int_digits_tail too | ||
| 2471 | ✗ | int_digits_added_zeros = 0; | |
| 2472 | } | ||
| 2473 | } | ||
| 2474 | ✗ | tmp_uint = (uint)(tmp_dec + (int_digits_end - int_digits_from) + | |
| 2475 | ✗ | (uint)(frac_digits_from - int_digits_tail_from) + | |
| 2476 | int_digits_added_zeros); | ||
| 2477 | } | ||
| 2478 | |||
| 2479 | /* | ||
| 2480 | Now write the formatted number | ||
| 2481 | |||
| 2482 | First the digits of the int_% parts. | ||
| 2483 | Do we have enough room to write these digits ? | ||
| 2484 | If the sign is defined and '-', we need one position for it | ||
| 2485 | */ | ||
| 2486 | |||
| 2487 | ✗ | if (field_length < tmp_uint + (int)(sign_char == '-')) { | |
| 2488 | // too big number, change to max or min number | ||
| 2489 | ✗ | Field_decimal::overflow(sign_char == '-'); | |
| 2490 | ✗ | return TYPE_WARN_OUT_OF_RANGE; | |
| 2491 | } | ||
| 2492 | |||
| 2493 | /* | ||
| 2494 | Tmp_left_pos is the position where the leftmost digit of | ||
| 2495 | the int_% parts will be written | ||
| 2496 | */ | ||
| 2497 | ✗ | tmp_left_pos = pos = to + (uint)(field_length - tmp_uint); | |
| 2498 | |||
| 2499 | // Write all digits of the int_% parts | ||
| 2500 | ✗ | while (int_digits_from != int_digits_end) *pos++ = *int_digits_from++; | |
| 2501 | |||
| 2502 | ✗ | if (expo_sign_char == '+') { | |
| 2503 | ✗ | while (int_digits_tail_from != frac_digits_from) | |
| 2504 | ✗ | *pos++ = *int_digits_tail_from++; | |
| 2505 | ✗ | while (int_digits_added_zeros-- > 0) *pos++ = '0'; | |
| 2506 | } | ||
| 2507 | /* | ||
| 2508 | Note the position where the rightmost digit of the int_% parts has been | ||
| 2509 | written (this is to later check if the int_% parts contained nothing, | ||
| 2510 | meaning an extra 0 is needed). | ||
| 2511 | */ | ||
| 2512 | ✗ | tmp_right_pos = pos; | |
| 2513 | |||
| 2514 | /* | ||
| 2515 | Step back to the position of the leftmost digit of the int_% parts, | ||
| 2516 | to write sign and fill with zeros or blanks or prezeros. | ||
| 2517 | */ | ||
| 2518 | ✗ | pos = tmp_left_pos - 1; | |
| 2519 | ✗ | if (zerofill) { | |
| 2520 | ✗ | left_wall = to - 1; | |
| 2521 | ✗ | while (pos > left_wall) // Fill with zeros | |
| 2522 | ✗ | *pos-- = '0'; | |
| 2523 | } else { | ||
| 2524 | ✗ | left_wall = to + (sign_char != 0) - 1; | |
| 2525 | ✗ | if (!expo_sign_char) // If exponent was specified, ignore prezeros | |
| 2526 | { | ||
| 2527 | ✗ | for (; pos > left_wall && pre_zeros_from != pre_zeros_end; | |
| 2528 | pre_zeros_from++) | ||
| 2529 | ✗ | *pos-- = '0'; | |
| 2530 | } | ||
| 2531 | ✗ | if (pos == tmp_right_pos - 1) | |
| 2532 | ✗ | *pos-- = '0'; // no 0 has ever been written, so write one | |
| 2533 | ✗ | left_wall = to - 1; | |
| 2534 | ✗ | if (sign_char && pos != left_wall) { | |
| 2535 | /* Write sign if possible (it is if sign is '-') */ | ||
| 2536 | ✗ | *pos-- = sign_char; | |
| 2537 | } | ||
| 2538 | ✗ | while (pos != left_wall) *pos-- = ' '; // fill with blanks | |
| 2539 | } | ||
| 2540 | |||
| 2541 | /* | ||
| 2542 | Write digits of the frac_% parts ; | ||
| 2543 | Depending on thd->check_for_truncated_fields, we may also want | ||
| 2544 | to know if some non-zero tail of these parts will | ||
| 2545 | be truncated (for example, 0.002->0.00 will generate a warning, | ||
| 2546 | while 0.000->0.00 will not) | ||
| 2547 | (and 0E1000000000 will not, while 1E-1000000000 will) | ||
| 2548 | */ | ||
| 2549 | |||
| 2550 | ✗ | pos = to + (uint)(field_length - tmp_dec); // Calculate post to '.' | |
| 2551 | ✗ | right_wall = to + field_length; | |
| 2552 | ✗ | if (pos != right_wall) *pos++ = '.'; | |
| 2553 | |||
| 2554 | ✗ | if (expo_sign_char == '-') { | |
| 2555 | ✗ | while (frac_digits_added_zeros-- > 0) { | |
| 2556 | ✗ | if (pos == right_wall) { | |
| 2557 | ✗ | if (thd->check_for_truncated_fields && | |
| 2558 | ✗ | !has_incremented_num_truncated_fields) | |
| 2559 | ✗ | break; // Go on below to see if we lose non zero digits | |
| 2560 | ✗ | return TYPE_OK; | |
| 2561 | } | ||
| 2562 | ✗ | *pos++ = '0'; | |
| 2563 | } | ||
| 2564 | ✗ | while (int_digits_end != frac_digits_head_end) { | |
| 2565 | ✗ | tmp_char = *int_digits_end++; | |
| 2566 | ✗ | if (pos == right_wall) { | |
| 2567 | ✗ | if (tmp_char != '0') // Losing a non zero digit ? | |
| 2568 | { | ||
| 2569 | ✗ | if (!has_incremented_num_truncated_fields) | |
| 2570 | ✗ | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); | |
| 2571 | ✗ | return TYPE_OK; | |
| 2572 | } | ||
| 2573 | ✗ | continue; | |
| 2574 | } | ||
| 2575 | ✗ | *pos++ = tmp_char; | |
| 2576 | } | ||
| 2577 | } | ||
| 2578 | |||
| 2579 | ✗ | for (; frac_digits_from != frac_digits_end;) { | |
| 2580 | ✗ | tmp_char = *frac_digits_from++; | |
| 2581 | ✗ | if (pos == right_wall) { | |
| 2582 | ✗ | if (tmp_char != '0') // Losing a non zero digit ? | |
| 2583 | { | ||
| 2584 | ✗ | if (!has_incremented_num_truncated_fields) { | |
| 2585 | /* | ||
| 2586 | This is a note, not a warning, as we don't want to abort | ||
| 2587 | when we cut decimals in strict mode | ||
| 2588 | */ | ||
| 2589 | ✗ | set_warning(Sql_condition::SL_NOTE, WARN_DATA_TRUNCATED, 1); | |
| 2590 | } | ||
| 2591 | ✗ | return TYPE_OK; | |
| 2592 | } | ||
| 2593 | ✗ | continue; | |
| 2594 | } | ||
| 2595 | ✗ | *pos++ = tmp_char; | |
| 2596 | } | ||
| 2597 | |||
| 2598 | ✗ | while (pos != right_wall) *pos++ = '0'; // Fill with zeros at right of '.' | |
| 2599 | ✗ | return TYPE_OK; | |
| 2600 | } | ||
| 2601 | |||
| 2602 | ✗ | type_conversion_status Field_decimal::store(double nr) { | |
| 2603 | ✗ | ASSERT_COLUMN_MARKED_FOR_WRITE; | |
| 2604 | ✗ | if (is_unsigned() && nr < 0) { | |
| 2605 | ✗ | overflow(true); | |
| 2606 | ✗ | return TYPE_WARN_OUT_OF_RANGE; | |
| 2607 | } | ||
| 2608 | |||
| 2609 | ✗ | if (!std::isfinite(nr)) // Handle infinity as special case | |
| 2610 | { | ||
| 2611 | ✗ | overflow(nr < 0.0); | |
| 2612 | ✗ | return TYPE_WARN_OUT_OF_RANGE; | |
| 2613 | } | ||
| 2614 | |||
| 2615 | size_t i; | ||
| 2616 | size_t length; | ||
| 2617 | uchar fyllchar, *to; | ||
| 2618 | char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE]; | ||
| 2619 | |||
| 2620 | ✗ | fyllchar = zerofill ? '0' : ' '; | |
| 2621 | ✗ | length = my_fcvt(nr, dec, buff, nullptr); | |
| 2622 | |||
| 2623 | ✗ | if (length > field_length) { | |
| 2624 | ✗ | overflow(nr < 0.0); | |
| 2625 | ✗ | return TYPE_WARN_OUT_OF_RANGE; | |
| 2626 | } else { | ||
| 2627 | ✗ | to = ptr; | |
| 2628 | ✗ | for (i = field_length - length; i-- > 0;) *to++ = fyllchar; | |
| 2629 | ✗ | memcpy(to, buff, length); | |
| 2630 | ✗ | return TYPE_OK; | |
| 2631 | } | ||
| 2632 | } | ||
| 2633 | |||
| 2634 | ✗ | type_conversion_status Field_decimal::store(longlong nr, bool unsigned_val) { | |
| 2635 | ✗ | ASSERT_COLUMN_MARKED_FOR_WRITE; | |
| 2636 | char buff[22]; | ||
| 2637 | uint length, int_part; | ||
| 2638 | char fyllchar; | ||
| 2639 | uchar *to; | ||
| 2640 | |||
| 2641 | ✗ | if (nr < 0 && is_unsigned() && !unsigned_val) { | |
| 2642 | ✗ | overflow(true); | |
| 2643 | ✗ | return TYPE_WARN_OUT_OF_RANGE; | |
| 2644 | } | ||
| 2645 | ✗ | length = (uint)(longlong10_to_str(nr, buff, unsigned_val ? 10 : -10) - buff); | |
| 2646 | ✗ | int_part = field_length - (dec ? dec + 1 : 0); | |
| 2647 | |||
| 2648 | ✗ | if (length > int_part) { | |
| 2649 | ✗ | overflow(!unsigned_val && nr < 0L); /* purecov: inspected */ | |
| 2650 | ✗ | return TYPE_WARN_OUT_OF_RANGE; | |
| 2651 | } | ||
| 2652 | |||
| 2653 | ✗ | fyllchar = zerofill ? '0' : ' '; | |
| 2654 | ✗ | to = ptr; | |
| 2655 | ✗ | for (uint i = int_part - length; i-- > 0;) *to++ = fyllchar; | |
| 2656 | ✗ | memcpy(to, buff, length); | |
| 2657 | ✗ | if (dec) { | |
| 2658 | ✗ | to[length] = '.'; | |
| 2659 | ✗ | memset(to + length + 1, '0', dec); | |
| 2660 | } | ||
| 2661 | ✗ | return TYPE_OK; | |
| 2662 | } | ||
| 2663 | |||
| 2664 | ✗ | double Field_decimal::val_real() const { | |
| 2665 | ✗ | ASSERT_COLUMN_MARKED_FOR_READ; | |
| 2666 | int not_used; | ||
| 2667 | const char *end_not_used; | ||
| 2668 | ✗ | return my_strntod(&my_charset_bin, pointer_cast<const char *>(ptr), | |
| 2669 | field_length, &end_not_used, ¬_used); | ||
| 2670 | } | ||
| 2671 | |||
| 2672 | ✗ | longlong Field_decimal::val_int() const { | |
| 2673 | ✗ | ASSERT_COLUMN_MARKED_FOR_READ; | |
| 2674 | int not_used; | ||
| 2675 | ✗ | if (is_unsigned()) | |
| 2676 | ✗ | return my_strntoull(&my_charset_bin, pointer_cast<const char *>(ptr), | |
| 2677 | field_length, 10, NULL, ¬_used); | ||
| 2678 | ✗ | return my_strntoll(&my_charset_bin, pointer_cast<const char *>(ptr), | |
| 2679 | field_length, 10, NULL, ¬_used); | ||
| 2680 | } | ||
| 2681 | |||
| 2682 | ✗ | String *Field_decimal::val_str(String *, String *val_ptr) const { | |
| 2683 | ✗ | ASSERT_COLUMN_MARKED_FOR_READ; | |
| 2684 | const uchar *str; | ||
| 2685 | size_t tmp_length; | ||
| 2686 | |||
| 2687 | ✗ | for (str = ptr; *str == ' '; str++) | |
| 2688 | ; | ||
| 2689 | ✗ | val_ptr->set_charset(&my_charset_numeric); | |
| 2690 | ✗ | tmp_length = (size_t)(str - ptr); | |
| 2691 | ✗ | if (field_length < tmp_length) // Error in data | |
| 2692 | ✗ | val_ptr->length(0); | |
| 2693 | else | ||
| 2694 | ✗ | val_ptr->set_ascii(pointer_cast<const char *>(str), | |
| 2695 | ✗ | field_length - tmp_length); | |
| 2696 | ✗ | return val_ptr; | |
| 2697 | } | ||
| 2698 | |||
| 2699 | /** | ||
| 2700 | Should be able to handle at least the following fixed decimal formats: | ||
| 2701 | 5.00 , -1.0, 05, -05, +5 with optional pre/end space | ||
| 2702 | */ | ||
| 2703 | |||
| 2704 | ✗ | int Field_decimal::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 2705 | const uchar *end; | ||
| 2706 | ✗ | int swap = 0; | |
| 2707 | /* First remove prefixes '0', ' ', and '-' */ | ||
| 2708 | ✗ | for (end = a_ptr + field_length; | |
| 2709 | ✗ | a_ptr != end && | |
| 2710 | ✗ | (*a_ptr == *b_ptr || ((my_isspace(&my_charset_bin, *a_ptr) || | |
| 2711 | ✗ | *a_ptr == '+' || *a_ptr == '0') && | |
| 2712 | ✗ | (my_isspace(&my_charset_bin, *b_ptr) || | |
| 2713 | ✗ | *b_ptr == '+' || *b_ptr == '0'))); | |
| 2714 | ✗ | a_ptr++, b_ptr++) { | |
| 2715 | ✗ | if (*a_ptr == '-') // If both numbers are negative | |
| 2716 | ✗ | swap = -1 ^ 1; // Swap result | |
| 2717 | } | ||
| 2718 | ✗ | if (a_ptr == end) return 0; | |
| 2719 | ✗ | if (*a_ptr == '-') return -1; | |
| 2720 | ✗ | if (*b_ptr == '-') return 1; | |
| 2721 | |||
| 2722 | ✗ | while (a_ptr != end) { | |
| 2723 | ✗ | if (*a_ptr++ != *b_ptr++) | |
| 2724 | ✗ | return swap ^ (a_ptr[-1] < b_ptr[-1] ? -1 : 1); // compare digits | |
| 2725 | } | ||
| 2726 | ✗ | return 0; | |
| 2727 | } | ||
| 2728 | |||
| 2729 | 195 | size_t Field_decimal::make_sort_key(uchar *to, size_t length) const { | |
| 2730 | uchar *str, *end; | ||
| 2731 | 195 | for (str = ptr, end = ptr + length; | |
| 2732 |
1/2✓ Branch 0 taken 195 times.
✗ Branch 1 not taken.
|
195 | str != end && |
| 2733 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 195 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 195 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 195 times.
|
195 | ((my_isspace(&my_charset_bin, *str) || *str == '+' || *str == '0')); |
| 2734 | str++) | ||
| 2735 | ✗ | *to++ = ' '; | |
| 2736 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 195 times.
|
195 | if (str == end) return length; /* purecov: inspected */ |
| 2737 | |||
| 2738 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 195 times.
|
195 | if (*str == '-') { |
| 2739 | ✗ | *to++ = 1; // Smaller than any number | |
| 2740 | ✗ | str++; | |
| 2741 | ✗ | while (str != end) | |
| 2742 | ✗ | if (my_isdigit(&my_charset_bin, *str)) | |
| 2743 | ✗ | *to++ = (char)('9' - *str++); | |
| 2744 | else | ||
| 2745 | ✗ | *to++ = *str++; | |
| 2746 | } else | ||
| 2747 | 195 | memcpy(to, str, (uint)(end - str)); | |
| 2748 | 195 | return length; | |
| 2749 | } | ||
| 2750 | |||
| 2751 | 1290 | void Field_decimal::sql_type(String &res) const { | |
| 2752 | 1290 | const CHARSET_INFO *cs = res.charset(); | |
| 2753 | 1290 | uint tmp = field_length; | |
| 2754 |
1/2✓ Branch 0 taken 1290 times.
✗ Branch 1 not taken.
|
1290 | if (!is_unsigned()) tmp--; |
| 2755 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1290 times.
|
1290 | if (dec) tmp--; |
| 2756 | 1290 | res.length(cs->cset->snprintf(cs, res.ptr(), res.alloced_length(), | |
| 2757 | 1290 | "decimal(%d,%d)", tmp, dec)); | |
| 2758 | 1290 | append_zerofill_and_unsigned(this, &res); | |
| 2759 | 1290 | } | |
| 2760 | |||
| 2761 | /**************************************************************************** | ||
| 2762 | ** Field_new_decimal | ||
| 2763 | ****************************************************************************/ | ||
| 2764 | |||
| 2765 | 906786 | Field_new_decimal::Field_new_decimal(uchar *ptr_arg, uint32 len_arg, | |
| 2766 | uchar *null_ptr_arg, uchar null_bit_arg, | ||
| 2767 | uchar auto_flags_arg, | ||
| 2768 | const char *field_name_arg, uint8 dec_arg, | ||
| 2769 | 906786 | bool zero_arg, bool unsigned_arg) | |
| 2770 | : Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg, | ||
| 2771 | 906786 | field_name_arg, dec_arg, zero_arg, unsigned_arg) { | |
| 2772 | 906786 | precision = | |
| 2773 | 906786 | std::min(my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg), | |
| 2774 | 906786 | uint(DECIMAL_MAX_PRECISION)); | |
| 2775 |
2/4✓ Branch 0 taken 906786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 906786 times.
✗ Branch 3 not taken.
|
906786 | assert((precision <= DECIMAL_MAX_PRECISION) && (dec <= DECIMAL_MAX_SCALE)); |
| 2776 |
1/2✓ Branch 0 taken 906786 times.
✗ Branch 1 not taken.
|
906786 | bin_size = my_decimal_get_binary_size(precision, dec); |
| 2777 | 906786 | } | |
| 2778 | |||
| 2779 | 430120 | Field_new_decimal::Field_new_decimal(uint32 len_arg, bool is_nullable_arg, | |
| 2780 | const char *name, uint8 dec_arg, | ||
| 2781 | 430120 | bool unsigned_arg) | |
| 2782 | : Field_num(nullptr, len_arg, | ||
| 2783 | is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE, name, | ||
| 2784 |
2/2✓ Branch 0 taken 360479 times.
✓ Branch 1 taken 69641 times.
|
430120 | dec_arg, false, unsigned_arg) { |
| 2785 | 430120 | precision = | |
| 2786 | 430120 | std::min(my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg), | |
| 2787 | 430120 | uint(DECIMAL_MAX_PRECISION)); | |
| 2788 |
2/4✓ Branch 0 taken 430120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 430120 times.
✗ Branch 3 not taken.
|
430120 | assert((precision <= DECIMAL_MAX_PRECISION) && (dec <= DECIMAL_MAX_SCALE)); |
| 2789 |
1/2✓ Branch 0 taken 430120 times.
✗ Branch 1 not taken.
|
430120 | bin_size = my_decimal_get_binary_size(precision, dec); |
| 2790 | 430120 | } | |
| 2791 | |||
| 2792 | 430117 | Field *Field_new_decimal::create_from_item(const Item *item) { | |
| 2793 | 430117 | uint8 dec = item->decimals; | |
| 2794 | 430117 | uint8 intg = item->decimal_precision() - dec; | |
| 2795 | 430117 | uint32 len = item->max_char_length(); | |
| 2796 | |||
| 2797 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 430117 times.
|
430117 | assert(item->result_type() == DECIMAL_RESULT); |
| 2798 | |||
| 2799 | /* | ||
| 2800 | Trying to put too many digits overall in a DECIMAL(prec,dec) | ||
| 2801 | will always throw a warning. We must limit dec to | ||
| 2802 | DECIMAL_MAX_SCALE however to prevent an assert() later. | ||
| 2803 | */ | ||
| 2804 | |||
| 2805 |
2/2✓ Branch 0 taken 34694 times.
✓ Branch 1 taken 395423 times.
|
430117 | if (dec > 0) { |
| 2806 | signed int overflow; | ||
| 2807 | |||
| 2808 | 34694 | dec = min<int>(dec, DECIMAL_MAX_SCALE); | |
| 2809 | |||
| 2810 | /* | ||
| 2811 | If the value still overflows the field with the corrected dec, | ||
| 2812 | we'll throw out decimals rather than integers. This is still | ||
| 2813 | bad and of course throws a truncation warning. | ||
| 2814 | +1: for decimal point | ||
| 2815 | */ | ||
| 2816 | |||
| 2817 | const int required_length = | ||
| 2818 | 34694 | my_decimal_precision_to_length(intg + dec, dec, item->unsigned_flag); | |
| 2819 | |||
| 2820 | 34694 | overflow = required_length - len; | |
| 2821 | |||
| 2822 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 34694 times.
|
34694 | if (overflow > 0) |
| 2823 | ✗ | dec = max(0, dec - overflow); // too long, discard fract | |
| 2824 | else | ||
| 2825 | /* Corrected value fits. */ | ||
| 2826 | 34694 | len = required_length; | |
| 2827 | } | ||
| 2828 | 430117 | return new (*THR_MALLOC) | |
| 2829 | 430117 | Field_new_decimal(len, item->is_nullable(), item->item_name.ptr(), dec, | |
| 2830 |
2/4✓ Branch 0 taken 430117 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 430117 times.
✗ Branch 3 not taken.
|
430117 | item->unsigned_flag); |
| 2831 | } | ||
| 2832 | |||
| 2833 | 622347 | type_conversion_status Field_new_decimal::reset() { | |
| 2834 | 622347 | (void)my_decimal2binary(0, &decimal_zero, ptr, precision, dec); | |
| 2835 | 622347 | return TYPE_OK; | |
| 2836 | } | ||
| 2837 | |||
| 2838 | /** | ||
| 2839 | Generate max/min decimal value in case of overflow. | ||
| 2840 | |||
| 2841 | @param decimal_value buffer for value | ||
| 2842 | @param sign sign of value which caused overflow | ||
| 2843 | */ | ||
| 2844 | |||
| 2845 | 670 | void Field_new_decimal::set_value_on_overflow(my_decimal *decimal_value, | |
| 2846 | bool sign) const { | ||
| 2847 |
1/2✓ Branch 0 taken 670 times.
✗ Branch 1 not taken.
|
670 | DBUG_TRACE; |
| 2848 |
1/2✓ Branch 0 taken 670 times.
✗ Branch 1 not taken.
|
670 | max_my_decimal(decimal_value, precision, decimals()); |
| 2849 |
2/2✓ Branch 0 taken 106 times.
✓ Branch 1 taken 564 times.
|
670 | if (sign) { |
| 2850 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 103 times.
|
106 | if (is_unsigned()) |
| 2851 | 3 | my_decimal_set_zero(decimal_value); | |
| 2852 | else | ||
| 2853 | 103 | decimal_value->sign(true); | |
| 2854 | } | ||
| 2855 | 670 | } | |
| 2856 | |||
| 2857 | /** | ||
| 2858 | Store decimal value in the binary buffer. | ||
| 2859 | |||
| 2860 | Checks if decimal_value fits into field size. | ||
| 2861 | If it does, stores the decimal in the buffer using binary format. | ||
| 2862 | Otherwise sets maximal number that can be stored in the field. | ||
| 2863 | |||
| 2864 | @param decimal_value my_decimal | ||
| 2865 | |||
| 2866 | @retval | ||
| 2867 | 0 ok | ||
| 2868 | @retval | ||
| 2869 | 1 error | ||
| 2870 | */ | ||
| 2871 | 1627923 | type_conversion_status Field_new_decimal::store_value( | |
| 2872 | const my_decimal *decimal_value) { | ||
| 2873 |
4/6✓ Branch 0 taken 1627923 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1612373 times.
✓ Branch 3 taken 15550 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1612374 times.
|
1627923 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 2874 | 1627924 | type_conversion_status error = TYPE_OK; | |
| 2875 |
1/2✓ Branch 0 taken 1627924 times.
✗ Branch 1 not taken.
|
1627924 | DBUG_TRACE; |
| 2876 | #ifndef NDEBUG | ||
| 2877 | { | ||
| 2878 | char dbug_buff[DECIMAL_MAX_STR_LENGTH + 2]; | ||
| 2879 |
3/10✓ Branch 0 taken 1627924 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1627924 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1627924 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
1627924 | DBUG_PRINT("enter", |
| 2880 | ("value: %s", dbug_decimal_as_string(dbug_buff, decimal_value))); | ||
| 2881 | } | ||
| 2882 | #endif | ||
| 2883 | |||
| 2884 | /* check that we do not try to write negative value in unsigned field */ | ||
| 2885 |
6/6✓ Branch 0 taken 7124 times.
✓ Branch 1 taken 1620799 times.
✓ Branch 2 taken 206 times.
✓ Branch 3 taken 6918 times.
✓ Branch 4 taken 206 times.
✓ Branch 5 taken 1627717 times.
|
1627924 | if (is_unsigned() && decimal_value->sign()) { |
| 2886 |
3/8✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 206 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
206 | DBUG_PRINT("info", ("unsigned overflow")); |
| 2887 |
1/2✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
|
206 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); |
| 2888 | 206 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 2889 | 206 | decimal_value = &decimal_zero; | |
| 2890 | } | ||
| 2891 | #ifndef NDEBUG | ||
| 2892 | { | ||
| 2893 | char dbug_buff[DECIMAL_MAX_STR_LENGTH + 2]; | ||
| 2894 |
3/10✓ Branch 0 taken 1627924 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1627924 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1627924 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
1627923 | DBUG_PRINT("info", |
| 2895 | ("saving with precision %d scale: %d value %s", (int)precision, | ||
| 2896 | (int)dec, dbug_decimal_as_string(dbug_buff, decimal_value))); | ||
| 2897 | } | ||
| 2898 | #endif | ||
| 2899 | |||
| 2900 | 3255848 | int err = my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, | |
| 2901 |
1/2✓ Branch 0 taken 1627924 times.
✗ Branch 1 not taken.
|
1627924 | decimal_value, ptr, precision, dec); |
| 2902 |
3/4✓ Branch 0 taken 1627923 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 569 times.
✓ Branch 3 taken 1627354 times.
|
1627924 | if (warn_if_overflow(err)) { |
| 2903 | 569 | my_decimal buff; | |
| 2904 |
3/8✓ Branch 0 taken 569 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 569 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 569 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
569 | DBUG_PRINT("info", ("overflow")); |
| 2905 |
1/2✓ Branch 0 taken 569 times.
✗ Branch 1 not taken.
|
569 | set_value_on_overflow(&buff, decimal_value->sign()); |
| 2906 |
1/2✓ Branch 0 taken 569 times.
✗ Branch 1 not taken.
|
569 | my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec); |
| 2907 | 569 | } | |
| 2908 |
2/6✓ Branch 0 taken 1627924 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1627924 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1627923 | DBUG_EXECUTE("info", print_decimal_buff(decimal_value, ptr, bin_size);); |
| 2909 |
2/2✓ Branch 0 taken 6529 times.
✓ Branch 1 taken 1621394 times.
|
3255847 | return (err != E_DEC_OK) ? decimal_err_to_type_conv_status(err) : error; |
| 2910 | 1627923 | } | |
| 2911 | |||
| 2912 | 21263 | type_conversion_status Field_new_decimal::store( | |
| 2913 | const char *from, size_t length, const CHARSET_INFO *charset_arg) { | ||
| 2914 |
4/6✓ Branch 0 taken 21263 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8153 times.
✓ Branch 3 taken 13110 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8153 times.
|
21263 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 2915 | 21263 | my_decimal decimal_value; | |
| 2916 |
1/2✓ Branch 0 taken 21263 times.
✗ Branch 1 not taken.
|
21263 | DBUG_TRACE; |
| 2917 | |||
| 2918 |
1/2✓ Branch 0 taken 21263 times.
✗ Branch 1 not taken.
|
21263 | THD *thd = current_thd; |
| 2919 | |||
| 2920 | int err = | ||
| 2921 |
1/2✓ Branch 0 taken 21263 times.
✗ Branch 1 not taken.
|
21263 | str2my_decimal(E_DEC_FATAL_ERROR & ~(E_DEC_OVERFLOW | E_DEC_BAD_NUM), |
| 2922 | from, length, charset_arg, &decimal_value); | ||
| 2923 | |||
| 2924 |
8/8✓ Branch 0 taken 152 times.
✓ Branch 1 taken 21111 times.
✓ Branch 2 taken 150 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 29 times.
✓ Branch 5 taken 121 times.
✓ Branch 6 taken 29 times.
✓ Branch 7 taken 21234 times.
|
21263 | if (err != 0 && !thd->lex->is_ignore() && thd->is_strict_mode()) { |
| 2925 |
1/2✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
|
29 | ErrConvString errmsg(from, length, charset_arg); |
| 2926 | 29 | const Diagnostics_area *da = thd->get_stmt_da(); | |
| 2927 |
2/4✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
✗ Branch 3 not taken.
|
29 | push_warning_printf( |
| 2928 | thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, | ||
| 2929 | ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), "decimal", | ||
| 2930 | errmsg.ptr(), field_name, da->current_row_for_condition()); | ||
| 2931 |
3/4✓ Branch 0 taken 24 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
29 | if (err == E_DEC_BAD_NUM) return store_value(&decimal_value); |
| 2932 | // Ensure that we always store something for virtual generated columns. | ||
| 2933 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
5 | if (is_virtual_gcol()) (void)store_value(&decimal_value); |
| 2934 | 5 | return decimal_err_to_type_conv_status(err); | |
| 2935 | } | ||
| 2936 | |||
| 2937 |
2/2✓ Branch 0 taken 123 times.
✓ Branch 1 taken 21111 times.
|
21234 | if (err != 0) { |
| 2938 |
1/2✓ Branch 0 taken 123 times.
✗ Branch 1 not taken.
|
123 | set_decimal_warning(thd, this, err, &decimal_value, from, length, |
| 2939 | charset_arg); | ||
| 2940 | } | ||
| 2941 | #ifndef NDEBUG | ||
| 2942 | char dbug_buff[DECIMAL_MAX_STR_LENGTH + 2]; | ||
| 2943 |
3/10✓ Branch 0 taken 21234 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21234 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 21234 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
21234 | DBUG_PRINT("enter", |
| 2944 | ("value: %s", dbug_decimal_as_string(dbug_buff, &decimal_value))); | ||
| 2945 | #endif | ||
| 2946 | |||
| 2947 |
1/2✓ Branch 0 taken 21234 times.
✗ Branch 1 not taken.
|
21234 | type_conversion_status store_stat = store_value(&decimal_value); |
| 2948 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 81 times.
|
123 | return (err != 0 && err != E_DEC_BAD_NUM) |
| 2949 |
2/2✓ Branch 0 taken 123 times.
✓ Branch 1 taken 21111 times.
|
21357 | ? decimal_err_to_type_conv_status(err) |
| 2950 | 21234 | : store_stat; | |
| 2951 | 21263 | } | |
| 2952 | |||
| 2953 | 7276 | type_conversion_status store_internal_with_error_check(Field_new_decimal *field, | |
| 2954 | int err, | ||
| 2955 | my_decimal *value) { | ||
| 2956 | 7276 | THD *thd = current_thd; | |
| 2957 | |||
| 2958 | 7276 | type_conversion_status stat = TYPE_OK; | |
| 2959 |
2/2✓ Branch 0 taken 79 times.
✓ Branch 1 taken 7197 times.
|
7276 | if (err == E_DEC_OVERFLOW) { |
| 2960 | 79 | field->set_value_on_overflow(value, value->sign()); | |
| 2961 | 79 | stat = TYPE_WARN_OUT_OF_RANGE; | |
| 2962 |
2/2✓ Branch 0 taken 125 times.
✓ Branch 1 taken 7072 times.
|
7197 | } else if (err == E_DEC_TRUNCATED) { |
| 2963 | 125 | stat = TYPE_NOTE_TRUNCATED; | |
| 2964 | } | ||
| 2965 | 7276 | uint cond_count = thd->get_stmt_da()->cond_count(); | |
| 2966 | 7276 | type_conversion_status store_stat = field->store_value(value); | |
| 2967 |
2/2✓ Branch 0 taken 594 times.
✓ Branch 1 taken 6682 times.
|
7276 | if (store_stat != TYPE_OK) |
| 2968 | 594 | return store_stat; | |
| 2969 |
5/6✓ Branch 0 taken 155 times.
✓ Branch 1 taken 6527 times.
✓ Branch 2 taken 155 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 155 times.
✓ Branch 5 taken 6527 times.
|
6682 | else if (err != 0 && thd->get_stmt_da()->cond_count() == cond_count) { |
| 2970 | /* Only issue a warning if store_value doesn't issue an warning */ | ||
| 2971 | 155 | field->warn_if_overflow(err); | |
| 2972 | } | ||
| 2973 | 6682 | return stat; | |
| 2974 | } | ||
| 2975 | |||
| 2976 | /** | ||
| 2977 | @todo | ||
| 2978 | Fix following when double2my_decimal when double2decimal | ||
| 2979 | will return E_DEC_TRUNCATED always correctly | ||
| 2980 | */ | ||
| 2981 | |||
| 2982 | 1164 | type_conversion_status Field_new_decimal::store(double nr) { | |
| 2983 |
3/6✓ Branch 0 taken 1164 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1164 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1164 times.
|
1164 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 2984 |
1/2✓ Branch 0 taken 1164 times.
✗ Branch 1 not taken.
|
1164 | DBUG_TRACE; |
| 2985 | 1164 | my_decimal decimal_value; | |
| 2986 | |||
| 2987 |
1/2✓ Branch 0 taken 1164 times.
✗ Branch 1 not taken.
|
1164 | int conv_err = double2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr, |
| 2988 | &decimal_value); | ||
| 2989 |
1/2✓ Branch 0 taken 1164 times.
✗ Branch 1 not taken.
|
2328 | return store_internal_with_error_check(this, conv_err, &decimal_value); |
| 2990 | 1164 | } | |
| 2991 | |||
| 2992 | 6052 | type_conversion_status Field_new_decimal::store(longlong nr, | |
| 2993 | bool unsigned_val) { | ||
| 2994 |
4/6✓ Branch 0 taken 6052 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5940 times.
✓ Branch 3 taken 112 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5940 times.
|
6052 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 2995 |
1/2✓ Branch 0 taken 6052 times.
✗ Branch 1 not taken.
|
6052 | DBUG_TRACE; |
| 2996 | 6052 | my_decimal decimal_value; | |
| 2997 |
1/2✓ Branch 0 taken 6052 times.
✗ Branch 1 not taken.
|
6052 | int conv_err = int2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr, |
| 2998 | unsigned_val, &decimal_value); | ||
| 2999 |
1/2✓ Branch 0 taken 6052 times.
✗ Branch 1 not taken.
|
12104 | return store_internal_with_error_check(this, conv_err, &decimal_value); |
| 3000 | 6052 | } | |
| 3001 | |||
| 3002 | 1599387 | type_conversion_status Field_new_decimal::store_decimal( | |
| 3003 | const my_decimal *decimal_value) { | ||
| 3004 |
4/6✓ Branch 0 taken 1599387 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1597057 times.
✓ Branch 3 taken 2330 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1597058 times.
|
1599387 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3005 | 1599388 | return store_value(decimal_value); | |
| 3006 | } | ||
| 3007 | |||
| 3008 | 2 | type_conversion_status Field_new_decimal::store_time(MYSQL_TIME *ltime, uint8) { | |
| 3009 | 2 | my_decimal decimal_value; | |
| 3010 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | return store_value(date2my_decimal(ltime, &decimal_value)); |
| 3011 | 2 | } | |
| 3012 | |||
| 3013 | 4620 | double Field_new_decimal::val_real() const { | |
| 3014 |
4/6✓ Branch 0 taken 4620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4619 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4619 times.
|
4620 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3015 | double dbl; | ||
| 3016 | 4620 | my_decimal decimal_value; | |
| 3017 |
2/4✓ Branch 0 taken 4620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4620 times.
✗ Branch 3 not taken.
|
4620 | my_decimal2double(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), &dbl); |
| 3018 | 4620 | return dbl; | |
| 3019 | 4620 | } | |
| 3020 | |||
| 3021 | 535 | longlong Field_new_decimal::val_int() const { | |
| 3022 |
3/6✓ Branch 0 taken 535 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 535 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 535 times.
|
535 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3023 | longlong i; | ||
| 3024 | 535 | my_decimal decimal_value; | |
| 3025 |
2/4✓ Branch 0 taken 535 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 535 times.
✗ Branch 3 not taken.
|
535 | my_decimal2int(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), is_unsigned(), |
| 3026 | &i); | ||
| 3027 | 535 | return i; | |
| 3028 | 535 | } | |
| 3029 | |||
| 3030 | 1747954 | my_decimal *Field_new_decimal::val_decimal(my_decimal *decimal_value) const { | |
| 3031 |
4/6✓ Branch 0 taken 1747954 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1687998 times.
✓ Branch 3 taken 59956 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1687998 times.
|
1747954 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3032 |
1/2✓ Branch 0 taken 1747955 times.
✗ Branch 1 not taken.
|
1747954 | DBUG_TRACE; |
| 3033 | 1747955 | binary2my_decimal(E_DEC_FATAL_ERROR, ptr, decimal_value, precision, dec, | |
| 3034 |
1/2✓ Branch 0 taken 1747954 times.
✗ Branch 1 not taken.
|
1747955 | m_keep_precision); |
| 3035 |
2/6✓ Branch 0 taken 1747954 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1747954 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1747954 | DBUG_EXECUTE("info", print_decimal_buff(decimal_value, ptr, bin_size);); |
| 3036 | 1747955 | return decimal_value; | |
| 3037 | 1747954 | } | |
| 3038 | |||
| 3039 | 85861 | String *Field_new_decimal::val_str(String *val_buffer, String *) const { | |
| 3040 |
4/6✓ Branch 0 taken 85861 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26121 times.
✓ Branch 3 taken 59740 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 26121 times.
|
85861 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3041 | 85861 | my_decimal decimal_value; | |
| 3042 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 85749 times.
|
85861 | uint fixed_precision = zerofill ? precision : 0; |
| 3043 |
1/2✓ Branch 0 taken 85861 times.
✗ Branch 1 not taken.
|
85861 | my_decimal2string(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), |
| 3044 |
1/2✓ Branch 0 taken 85861 times.
✗ Branch 1 not taken.
|
85861 | fixed_precision, dec, val_buffer); |
| 3045 | 85861 | val_buffer->set_charset(&my_charset_numeric); | |
| 3046 | 85861 | return val_buffer; | |
| 3047 | 85861 | } | |
| 3048 | |||
| 3049 | 12 | bool Field_new_decimal::get_date(MYSQL_TIME *ltime, | |
| 3050 | my_time_flags_t fuzzydate) const { | ||
| 3051 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | my_decimal buf, *decimal_value = val_decimal(&buf); |
| 3052 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (!decimal_value) { |
| 3053 | ✗ | set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME); | |
| 3054 | ✗ | return true; | |
| 3055 | } | ||
| 3056 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | return my_decimal_to_datetime_with_warn(decimal_value, ltime, fuzzydate); |
| 3057 | 12 | } | |
| 3058 | |||
| 3059 | 20 | bool Field_new_decimal::get_time(MYSQL_TIME *ltime) const { | |
| 3060 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | my_decimal buf, *decimal_value = val_decimal(&buf); |
| 3061 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (!decimal_value) { |
| 3062 | ✗ | set_zero_time(ltime, MYSQL_TIMESTAMP_TIME); | |
| 3063 | ✗ | return true; | |
| 3064 | } | ||
| 3065 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | return my_decimal_to_time_with_warn(decimal_value, ltime); |
| 3066 | 20 | } | |
| 3067 | |||
| 3068 | 3933 | int Field_new_decimal::cmp(const uchar *a, const uchar *b) const { | |
| 3069 | 3933 | return memcmp(a, b, bin_size); | |
| 3070 | } | ||
| 3071 | |||
| 3072 | 9197 | size_t Field_new_decimal::make_sort_key(uchar *buff, size_t length) const { | |
| 3073 | 9197 | memcpy(buff, ptr, min(length, static_cast<size_t>(bin_size))); | |
| 3074 | 9197 | return length; | |
| 3075 | } | ||
| 3076 | |||
| 3077 | 302038 | void Field_new_decimal::sql_type(String &str) const { | |
| 3078 | 302038 | const CHARSET_INFO *cs = str.charset(); | |
| 3079 | 302038 | str.length(cs->cset->snprintf(cs, str.ptr(), str.alloced_length(), | |
| 3080 | 302038 | "decimal(%d,%d)", precision, (int)dec)); | |
| 3081 | 302038 | append_zerofill_and_unsigned(this, &str); | |
| 3082 | 302038 | } | |
| 3083 | |||
| 3084 | /** | ||
| 3085 | Save the field metadata for new decimal fields. | ||
| 3086 | |||
| 3087 | Saves the precision in the first byte and decimals() in the second | ||
| 3088 | byte of the field metadata array at index of *metadata_ptr and | ||
| 3089 | *(metadata_ptr + 1). | ||
| 3090 | |||
| 3091 | @param metadata_ptr First byte of field metadata | ||
| 3092 | |||
| 3093 | @returns number of bytes written to metadata_ptr | ||
| 3094 | */ | ||
| 3095 | 25910 | int Field_new_decimal::do_save_field_metadata(uchar *metadata_ptr) const { | |
| 3096 | 25910 | *metadata_ptr = precision; | |
| 3097 | 25910 | *(metadata_ptr + 1) = decimals(); | |
| 3098 | 25910 | return 2; | |
| 3099 | } | ||
| 3100 | |||
| 3101 | /** | ||
| 3102 | Returns the number of bytes field uses in row-based replication | ||
| 3103 | row packed size. | ||
| 3104 | |||
| 3105 | This method is used in row-based replication to determine the number | ||
| 3106 | of bytes that the field consumes in the row record format. This is | ||
| 3107 | used to skip fields in the master that do not exist on the slave. | ||
| 3108 | |||
| 3109 | @param field_metadata Encoded size in field metadata | ||
| 3110 | |||
| 3111 | @returns The size of the field based on the field metadata. | ||
| 3112 | */ | ||
| 3113 | ✗ | uint Field_new_decimal::pack_length_from_metadata(uint field_metadata) const { | |
| 3114 | ✗ | uint const source_precision = (field_metadata >> 8U) & 0x00ff; | |
| 3115 | ✗ | uint const source_decimal = field_metadata & 0x00ff; | |
| 3116 | uint const source_size = | ||
| 3117 | ✗ | my_decimal_get_binary_size(source_precision, source_decimal); | |
| 3118 | ✗ | return (source_size); | |
| 3119 | } | ||
| 3120 | |||
| 3121 | /** | ||
| 3122 | Check to see if field size is compatible with destination. | ||
| 3123 | |||
| 3124 | This method is used in row-based replication to verify that the slave's | ||
| 3125 | field size is less than or equal to the master's field size. The | ||
| 3126 | encoded field metadata (from the master or source) is decoded and compared | ||
| 3127 | to the size of this field (the slave or destination). | ||
| 3128 | |||
| 3129 | @param field_metadata Encoded size in field metadata | ||
| 3130 | @param order_var Pointer to variable where the order | ||
| 3131 | between the source field and this field | ||
| 3132 | will be returned. | ||
| 3133 | |||
| 3134 | @return @c true | ||
| 3135 | */ | ||
| 3136 | 1719 | bool Field_new_decimal::compatible_field_size(uint field_metadata, | |
| 3137 | Relay_log_info *, uint16, | ||
| 3138 | int *order_var) const { | ||
| 3139 | 1719 | uint const source_precision = (field_metadata >> 8U) & 0x00ff; | |
| 3140 | 1719 | uint const source_decimal = field_metadata & 0x00ff; | |
| 3141 | 1719 | int order = compare(source_precision, precision); | |
| 3142 |
2/2✓ Branch 0 taken 1699 times.
✓ Branch 1 taken 20 times.
|
1719 | *order_var = order != 0 ? order : compare(source_decimal, dec); |
| 3143 | 1719 | return true; | |
| 3144 | } | ||
| 3145 | |||
| 3146 | 1091 | uint Field_new_decimal::is_equal(const Create_field *new_field) const { | |
| 3147 |
2/2✓ Branch 0 taken 1039 times.
✓ Branch 1 taken 33 times.
|
2163 | return (new_field->sql_type == real_type()) && |
| 3148 | 1072 | (Overlaps(new_field->flags, UNSIGNED_FLAG) == | |
| 3149 |
1/2✓ Branch 0 taken 1039 times.
✗ Branch 1 not taken.
|
2111 | is_flag_set(UNSIGNED_FLAG)) && |
| 3150 | 1039 | (Overlaps(new_field->flags, AUTO_INCREMENT_FLAG) == | |
| 3151 | 1039 | is_flag_set(AUTO_INCREMENT_FLAG)) && | |
| 3152 |
4/4✓ Branch 0 taken 1072 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 1013 times.
✓ Branch 3 taken 26 times.
|
3176 | (new_field->max_display_width_in_bytes() == max_display_length()) && |
| 3153 |
2/2✓ Branch 0 taken 1005 times.
✓ Branch 1 taken 8 times.
|
2104 | (new_field->decimals == dec); |
| 3154 | } | ||
| 3155 | |||
| 3156 | /** | ||
| 3157 | Unpack a decimal field from row data. | ||
| 3158 | |||
| 3159 | This method is used to unpack a decimal or numeric field from a master | ||
| 3160 | whose size of the field is less than that of the slave. | ||
| 3161 | |||
| 3162 | @param to Destination of the data | ||
| 3163 | @param from Source of the data | ||
| 3164 | @param param_data Precision (upper) and decimal (lower) values | ||
| 3165 | |||
| 3166 | @return New pointer into memory based on from + length of the data | ||
| 3167 | */ | ||
| 3168 | 64828 | const uchar *Field_new_decimal::unpack(uchar *to, const uchar *from, | |
| 3169 | uint param_data) { | ||
| 3170 |
2/2✓ Branch 0 taken 60206 times.
✓ Branch 1 taken 4622 times.
|
64828 | if (param_data == 0) return Field::unpack(to, from, param_data); |
| 3171 | |||
| 3172 | 4622 | uint from_precision = (param_data & 0xff00) >> 8U; | |
| 3173 | 4622 | uint from_decimal = param_data & 0x00ff; | |
| 3174 | 4622 | uint length = pack_length(); | |
| 3175 | 4622 | uint from_pack_len = my_decimal_get_binary_size(from_precision, from_decimal); | |
| 3176 |
2/4✓ Branch 0 taken 4622 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4622 times.
|
4622 | uint len = (param_data && (from_pack_len < length)) ? from_pack_len : length; |
| 3177 |
1/2✓ Branch 0 taken 4622 times.
✗ Branch 1 not taken.
|
4622 | if ((from_pack_len && (from_pack_len < length)) || |
| 3178 |
4/8✓ Branch 0 taken 4622 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4622 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4622 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4622 times.
|
9244 | (from_precision < precision) || (from_decimal < decimals())) { |
| 3179 | /* | ||
| 3180 | If the master's data is smaller than the slave, we need to convert | ||
| 3181 | the binary to decimal then resize the decimal converting it back to | ||
| 3182 | a decimal and write that to the raw data buffer. | ||
| 3183 | */ | ||
| 3184 | decimal_digit_t dec_buf[DECIMAL_MAX_PRECISION]; | ||
| 3185 | decimal_t dec_val; | ||
| 3186 | ✗ | dec_val.len = from_precision; | |
| 3187 | ✗ | dec_val.buf = dec_buf; | |
| 3188 | /* | ||
| 3189 | Note: bin2decimal does not change the length of the field. So it is | ||
| 3190 | just the first step the resizing operation. The second step does the | ||
| 3191 | resizing using the precision and decimals from the slave. | ||
| 3192 | */ | ||
| 3193 | ✗ | bin2decimal(from, &dec_val, from_precision, from_decimal); | |
| 3194 | ✗ | decimal2bin(&dec_val, to, precision, decimals()); | |
| 3195 | } else | ||
| 3196 | 4622 | memcpy(to, from, len); // Sizes are the same, just copy the data. | |
| 3197 | 4622 | return from + len; | |
| 3198 | } | ||
| 3199 | |||
| 3200 | 45443 | bool Field_new_decimal::send_to_protocol(Protocol *protocol) const { | |
| 3201 |
4/6✓ Branch 0 taken 45443 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18081 times.
✓ Branch 3 taken 27362 times.
✓ Branch 4 taken 18081 times.
✗ Branch 5 not taken.
|
45443 | if (is_null()) return protocol->store_null(); |
| 3202 | 27362 | my_decimal dec_value; | |
| 3203 |
2/4✓ Branch 0 taken 27362 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27362 times.
✗ Branch 3 not taken.
|
27362 | return protocol->store_decimal(val_decimal(&dec_value), |
| 3204 |
2/2✓ Branch 0 taken 2635 times.
✓ Branch 1 taken 24727 times.
|
54724 | zerofill ? precision : 0, dec); |
| 3205 | 27362 | } | |
| 3206 | |||
| 3207 | /**************************************************************************** | ||
| 3208 | ** tiny int | ||
| 3209 | ****************************************************************************/ | ||
| 3210 | |||
| 3211 | 516432 | type_conversion_status Field_tiny::store(const char *from, size_t len, | |
| 3212 | const CHARSET_INFO *cs) { | ||
| 3213 |
4/6✓ Branch 0 taken 516432 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 508709 times.
✓ Branch 3 taken 7723 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 508709 times.
|
516432 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3214 | longlong rnd; | ||
| 3215 | |||
| 3216 | const type_conversion_status error = | ||
| 3217 |
1/2✓ Branch 0 taken 516432 times.
✗ Branch 1 not taken.
|
516432 | get_int(cs, from, len, &rnd, 255, -128, 127); |
| 3218 | 516432 | ptr[0] = is_unsigned() ? (char)(ulonglong)rnd : (char)rnd; | |
| 3219 | 516432 | return error; | |
| 3220 | } | ||
| 3221 | |||
| 3222 | 9076 | type_conversion_status Field_tiny::store(double nr) { | |
| 3223 |
4/6✓ Branch 0 taken 9076 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9070 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9070 times.
|
9076 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3224 | 9076 | type_conversion_status error = TYPE_OK; | |
| 3225 | 9076 | nr = rint(nr); | |
| 3226 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 9053 times.
|
9076 | if (is_unsigned()) { |
| 3227 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 19 times.
|
23 | if (nr < 0.0) { |
| 3228 | 4 | *ptr = 0; | |
| 3229 | 4 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3230 | 4 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3231 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 15 times.
|
19 | } else if (nr > 255.0) { |
| 3232 | 4 | *ptr = (char)255; | |
| 3233 | 4 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3234 | 4 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3235 | } else | ||
| 3236 | 15 | *ptr = static_cast<unsigned char>(nr); | |
| 3237 | } else { | ||
| 3238 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 9031 times.
|
9053 | if (nr < -128.0) { |
| 3239 | 22 | *ptr = (char)-128; | |
| 3240 | 22 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3241 | 22 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3242 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 9003 times.
|
9031 | } else if (nr > 127.0) { |
| 3243 | 28 | *ptr = 127; | |
| 3244 | 28 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3245 | 28 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3246 | } else | ||
| 3247 | 9003 | *ptr = (char)(int)nr; | |
| 3248 | } | ||
| 3249 | 9076 | return error; | |
| 3250 | } | ||
| 3251 | |||
| 3252 | 63088307 | type_conversion_status Field_tiny::store(longlong nr, bool unsigned_val) { | |
| 3253 |
4/6✓ Branch 0 taken 63088307 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 63085191 times.
✓ Branch 3 taken 3116 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 63085191 times.
|
63088307 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3254 | 63088307 | type_conversion_status error = TYPE_OK; | |
| 3255 | |||
| 3256 |
2/2✓ Branch 0 taken 99563 times.
✓ Branch 1 taken 62988746 times.
|
63088307 | if (is_unsigned()) { |
| 3257 |
4/4✓ Branch 0 taken 109 times.
✓ Branch 1 taken 99454 times.
✓ Branch 2 taken 98 times.
✓ Branch 3 taken 11 times.
|
99563 | if (nr < 0 && !unsigned_val) { |
| 3258 | 98 | *ptr = 0; | |
| 3259 | 98 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3260 | 98 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3261 |
2/2✓ Branch 0 taken 61 times.
✓ Branch 1 taken 99404 times.
|
99465 | } else if ((ulonglong)nr > (ulonglong)255) { |
| 3262 | 61 | *ptr = (char)255; | |
| 3263 | 61 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3264 | 61 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3265 | } else | ||
| 3266 | 99404 | *ptr = (char)nr; | |
| 3267 | } else { | ||
| 3268 |
4/4✓ Branch 0 taken 5042 times.
✓ Branch 1 taken 62983704 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 5036 times.
|
62988746 | if (nr < 0 && unsigned_val) nr = 256; // Generate overflow |
| 3269 |
2/2✓ Branch 0 taken 107 times.
✓ Branch 1 taken 62988639 times.
|
62988746 | if (nr < -128) { |
| 3270 | 107 | *ptr = (char)-128; | |
| 3271 | 107 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3272 | 107 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3273 |
2/2✓ Branch 0 taken 299 times.
✓ Branch 1 taken 62988340 times.
|
62988639 | } else if (nr > 127) { |
| 3274 | 299 | *ptr = 127; | |
| 3275 | 299 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3276 | 299 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3277 | } else | ||
| 3278 | 62988340 | *ptr = (char)nr; | |
| 3279 | } | ||
| 3280 | 63088309 | return error; | |
| 3281 | } | ||
| 3282 | |||
| 3283 | 38 | double Field_tiny::val_real() const { | |
| 3284 |
3/6✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 38 times.
|
38 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
|
38 | int tmp = is_unsigned() ? (int)ptr[0] : (int)((signed char *)ptr)[0]; |
| 3286 | 38 | return (double)tmp; | |
| 3287 | } | ||
| 3288 | |||
| 3289 | 286018408 | longlong Field_tiny::val_int() const { | |
| 3290 |
4/6✓ Branch 0 taken 286018408 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 286016965 times.
✓ Branch 3 taken 1443 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 286016965 times.
|
286018408 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3291 |
2/2✓ Branch 0 taken 675257 times.
✓ Branch 1 taken 285343152 times.
|
286018408 | int tmp = is_unsigned() ? (int)ptr[0] : (int)((signed char *)ptr)[0]; |
| 3292 | 286018409 | return (longlong)tmp; | |
| 3293 | } | ||
| 3294 | |||
| 3295 | 76823 | String *Field_tiny::val_str(String *val_buffer, String *) const { | |
| 3296 |
4/6✓ Branch 0 taken 76823 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 67502 times.
✓ Branch 3 taken 9321 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 67502 times.
|
76823 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3297 | 76823 | const CHARSET_INFO *cs = &my_charset_numeric; | |
| 3298 | uint length; | ||
| 3299 | 76823 | uint mlength = max(field_length + 1, 5 * cs->mbmaxlen); | |
| 3300 | 76823 | val_buffer->alloc(mlength); | |
| 3301 | 76823 | char *to = val_buffer->ptr(); | |
| 3302 | |||
| 3303 |
2/2✓ Branch 0 taken 6659 times.
✓ Branch 1 taken 70164 times.
|
76823 | if (is_unsigned()) |
| 3304 | 6659 | length = (uint)cs->cset->long10_to_str(cs, to, mlength, 10, (long)*ptr); | |
| 3305 | else | ||
| 3306 | 70164 | length = (uint)cs->cset->long10_to_str(cs, to, mlength, -10, | |
| 3307 | 70164 | (long)*((signed char *)ptr)); | |
| 3308 | |||
| 3309 | 76823 | val_buffer->length(length); | |
| 3310 |
2/2✓ Branch 0 taken 1351 times.
✓ Branch 1 taken 75472 times.
|
76823 | if (zerofill) prepend_zeros(val_buffer); |
| 3311 | 76823 | val_buffer->set_charset(cs); | |
| 3312 | 76823 | return val_buffer; | |
| 3313 | } | ||
| 3314 | |||
| 3315 | 201021 | bool Field_tiny::send_to_protocol(Protocol *protocol) const { | |
| 3316 |
2/2✓ Branch 0 taken 3785 times.
✓ Branch 1 taken 197236 times.
|
201021 | if (is_null()) return protocol->store_null(); |
| 3317 | 197236 | return protocol->store_tiny(Field_tiny::val_int(), | |
| 3318 |
2/2✓ Branch 0 taken 16595 times.
✓ Branch 1 taken 180641 times.
|
394472 | zerofill ? field_length : 0); |
| 3319 | } | ||
| 3320 | |||
| 3321 | 124460 | int Field_tiny::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 3322 | signed char a, b; | ||
| 3323 | 124460 | a = (signed char)a_ptr[0]; | |
| 3324 | 124460 | b = (signed char)b_ptr[0]; | |
| 3325 |
2/2✓ Branch 0 taken 2716 times.
✓ Branch 1 taken 121744 times.
|
124460 | if (is_unsigned()) |
| 3326 |
4/4✓ Branch 0 taken 1317 times.
✓ Branch 1 taken 1399 times.
✓ Branch 2 taken 422 times.
✓ Branch 3 taken 895 times.
|
2716 | return ((uchar)a < (uchar)b) ? -1 : ((uchar)a > (uchar)b) ? 1 : 0; |
| 3327 |
4/4✓ Branch 0 taken 121259 times.
✓ Branch 1 taken 485 times.
✓ Branch 2 taken 235 times.
✓ Branch 3 taken 121024 times.
|
121744 | return (a < b) ? -1 : (a > b) ? 1 : 0; |
| 3328 | } | ||
| 3329 | |||
| 3330 | 66572 | size_t Field_tiny::make_sort_key(uchar *to, | |
| 3331 | size_t length [[maybe_unused]]) const { | ||
| 3332 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66572 times.
|
66572 | assert(length == 1); |
| 3333 |
2/2✓ Branch 0 taken 2101 times.
✓ Branch 1 taken 64471 times.
|
66572 | if (is_unsigned()) |
| 3334 | 2101 | *to = *ptr; | |
| 3335 | else | ||
| 3336 | 64471 | to[0] = (char)(ptr[0] ^ (uchar)128); /* Revers signbit */ | |
| 3337 | 66572 | return 1; | |
| 3338 | } | ||
| 3339 | |||
| 3340 | 336669 | void Field_tiny::sql_type(String &res) const { | |
| 3341 |
7/8✓ Branch 0 taken 293277 times.
✓ Branch 1 taken 43392 times.
✓ Branch 2 taken 292856 times.
✓ Branch 3 taken 421 times.
✓ Branch 4 taken 292856 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 292856 times.
✓ Branch 7 taken 43813 times.
|
336669 | if (field_length == 1 && !is_unsigned() && !zerofill) { |
| 3342 | // Print TINYINT(1) since connectors use this to indicate BOOLEAN | ||
| 3343 | 292856 | res.length(0); | |
| 3344 |
1/2✓ Branch 0 taken 292856 times.
✗ Branch 1 not taken.
|
292856 | res.append("tinyint(1)"); |
| 3345 | } else { | ||
| 3346 | 43813 | integer_sql_type(this, "tinyint", &res); | |
| 3347 | } | ||
| 3348 | 336669 | } | |
| 3349 | |||
| 3350 | /**************************************************************************** | ||
| 3351 | Field type short int (2 byte) | ||
| 3352 | ****************************************************************************/ | ||
| 3353 | |||
| 3354 | 1302 | type_conversion_status Field_short::store(const char *from, size_t len, | |
| 3355 | const CHARSET_INFO *cs) { | ||
| 3356 |
4/6✓ Branch 0 taken 1302 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 968 times.
✓ Branch 3 taken 334 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 968 times.
|
1302 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3357 | int store_tmp; | ||
| 3358 | longlong rnd; | ||
| 3359 | |||
| 3360 | const type_conversion_status error = | ||
| 3361 |
1/2✓ Branch 0 taken 1302 times.
✗ Branch 1 not taken.
|
1302 | get_int(cs, from, len, &rnd, UINT_MAX16, INT_MIN16, INT_MAX16); |
| 3362 | 1302 | store_tmp = is_unsigned() ? (int)(ulonglong)rnd : (int)rnd; | |
| 3363 |
1/2✓ Branch 0 taken 1302 times.
✗ Branch 1 not taken.
|
1302 | if (table->s->db_low_byte_first) |
| 3364 | 1302 | int2store(ptr, store_tmp); | |
| 3365 | else | ||
| 3366 | ✗ | shortstore(ptr, (short)store_tmp); | |
| 3367 | 1302 | return error; | |
| 3368 | } | ||
| 3369 | |||
| 3370 | 70 | type_conversion_status Field_short::store(double nr) { | |
| 3371 |
3/6✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 70 times.
|
70 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3372 | 70 | type_conversion_status error = TYPE_OK; | |
| 3373 | int16 res; | ||
| 3374 | 70 | nr = rint(nr); | |
| 3375 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 36 times.
|
70 | if (is_unsigned()) { |
| 3376 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 31 times.
|
34 | if (nr < 0) { |
| 3377 | 3 | res = 0; | |
| 3378 | 3 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3379 | 3 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3380 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | } else if (nr > UINT_MAX16) { |
| 3381 | ✗ | res = (int16)UINT_MAX16; | |
| 3382 | ✗ | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3383 | ✗ | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3384 | } else | ||
| 3385 | 31 | res = (int16)(uint16)nr; | |
| 3386 | } else { | ||
| 3387 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
|
36 | if (nr < INT_MIN16) { |
| 3388 | 18 | res = INT_MIN16; | |
| 3389 | 18 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3390 | 18 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3391 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | } else if (nr > INT_MAX16) { |
| 3392 | 18 | res = INT_MAX16; | |
| 3393 | 18 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3394 | 18 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3395 | } else | ||
| 3396 | ✗ | res = (int16)(int)nr; | |
| 3397 | } | ||
| 3398 |
1/2✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 | if (table->s->db_low_byte_first) |
| 3399 | 70 | int2store(ptr, res); | |
| 3400 | else | ||
| 3401 | ✗ | shortstore(ptr, res); | |
| 3402 | 70 | return error; | |
| 3403 | } | ||
| 3404 | |||
| 3405 | 632646 | type_conversion_status Field_short::store(longlong nr, bool unsigned_val) { | |
| 3406 |
4/6✓ Branch 0 taken 632646 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 632488 times.
✓ Branch 3 taken 158 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 632488 times.
|
632646 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3407 | 632646 | type_conversion_status error = TYPE_OK; | |
| 3408 | int16 res; | ||
| 3409 | |||
| 3410 |
2/2✓ Branch 0 taken 574994 times.
✓ Branch 1 taken 57652 times.
|
632646 | if (is_unsigned()) { |
| 3411 |
4/4✓ Branch 0 taken 81 times.
✓ Branch 1 taken 574913 times.
✓ Branch 2 taken 70 times.
✓ Branch 3 taken 11 times.
|
574994 | if (nr < 0L && !unsigned_val) { |
| 3412 | 70 | res = 0; | |
| 3413 | 70 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3414 | 70 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3415 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 574886 times.
|
574924 | } else if ((ulonglong)nr > (ulonglong)UINT_MAX16) { |
| 3416 | 38 | res = (int16)UINT_MAX16; | |
| 3417 | 38 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3418 | 38 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3419 | } else | ||
| 3420 | 574886 | res = (int16)(uint16)nr; | |
| 3421 | } else { | ||
| 3422 |
4/4✓ Branch 0 taken 636 times.
✓ Branch 1 taken 57016 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 630 times.
|
57652 | if (nr < 0 && unsigned_val) nr = UINT_MAX16 + 1; // Generate overflow |
| 3423 | |||
| 3424 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 57552 times.
|
57652 | if (nr < INT_MIN16) { |
| 3425 | 100 | res = INT_MIN16; | |
| 3426 | 100 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3427 | 100 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3428 |
2/2✓ Branch 0 taken 154 times.
✓ Branch 1 taken 57398 times.
|
57552 | } else if (nr > (longlong)INT_MAX16) { |
| 3429 | 154 | res = INT_MAX16; | |
| 3430 | 154 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3431 | 154 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3432 | } else | ||
| 3433 | 57398 | res = (int16)nr; | |
| 3434 | } | ||
| 3435 |
2/2✓ Branch 0 taken 632636 times.
✓ Branch 1 taken 10 times.
|
632646 | if (table->s->db_low_byte_first) |
| 3436 | 632636 | int2store(ptr, res); | |
| 3437 | else | ||
| 3438 | 10 | shortstore(ptr, res); | |
| 3439 | 632646 | return error; | |
| 3440 | } | ||
| 3441 | |||
| 3442 | 504 | double Field_short::val_real() const { | |
| 3443 |
3/6✓ Branch 0 taken 504 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 504 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 504 times.
|
504 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3444 | short j; | ||
| 3445 |
1/2✓ Branch 0 taken 504 times.
✗ Branch 1 not taken.
|
504 | if (table->s->db_low_byte_first) |
| 3446 | 504 | j = sint2korr(ptr); | |
| 3447 | else | ||
| 3448 | ✗ | j = shortget(ptr); | |
| 3449 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 492 times.
|
504 | return is_unsigned() ? (double)(unsigned short)j : (double)j; |
| 3450 | } | ||
| 3451 | |||
| 3452 | 232638 | longlong Field_short::val_int() const { | |
| 3453 |
4/6✓ Branch 0 taken 232638 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 232628 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 232628 times.
|
232638 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3454 | short j; | ||
| 3455 |
2/2✓ Branch 0 taken 232628 times.
✓ Branch 1 taken 10 times.
|
232638 | if (table->s->db_low_byte_first) |
| 3456 | 232628 | j = sint2korr(ptr); | |
| 3457 | else | ||
| 3458 | 10 | j = shortget(ptr); | |
| 3459 |
2/2✓ Branch 0 taken 154447 times.
✓ Branch 1 taken 78191 times.
|
232638 | return is_unsigned() ? (longlong)(unsigned short)j : (longlong)j; |
| 3460 | } | ||
| 3461 | |||
| 3462 | 7648 | String *Field_short::val_str(String *val_buffer, String *) const { | |
| 3463 |
4/6✓ Branch 0 taken 7648 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7287 times.
✓ Branch 3 taken 361 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 7287 times.
|
7648 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3464 | 7648 | const CHARSET_INFO *cs = &my_charset_numeric; | |
| 3465 | uint length; | ||
| 3466 | 7648 | uint mlength = max(field_length + 1, 7 * cs->mbmaxlen); | |
| 3467 | 7648 | val_buffer->alloc(mlength); | |
| 3468 | 7648 | char *to = val_buffer->ptr(); | |
| 3469 | short j; | ||
| 3470 |
1/2✓ Branch 0 taken 7648 times.
✗ Branch 1 not taken.
|
7648 | if (table->s->db_low_byte_first) |
| 3471 | 7648 | j = sint2korr(ptr); | |
| 3472 | else | ||
| 3473 | ✗ | j = shortget(ptr); | |
| 3474 | |||
| 3475 |
2/2✓ Branch 0 taken 3914 times.
✓ Branch 1 taken 3734 times.
|
7648 | if (is_unsigned()) |
| 3476 | 3914 | length = | |
| 3477 | 3914 | (uint)cs->cset->long10_to_str(cs, to, mlength, 10, (long)(uint16)j); | |
| 3478 | else | ||
| 3479 | 3734 | length = (uint)cs->cset->long10_to_str(cs, to, mlength, -10, (long)j); | |
| 3480 | 7648 | val_buffer->length(length); | |
| 3481 |
2/2✓ Branch 0 taken 152 times.
✓ Branch 1 taken 7496 times.
|
7648 | if (zerofill) prepend_zeros(val_buffer); |
| 3482 | 7648 | val_buffer->set_charset(cs); | |
| 3483 | 7648 | return val_buffer; | |
| 3484 | } | ||
| 3485 | |||
| 3486 | 74944 | bool Field_short::send_to_protocol(Protocol *protocol) const { | |
| 3487 |
2/2✓ Branch 0 taken 3709 times.
✓ Branch 1 taken 71235 times.
|
74944 | if (is_null()) return protocol->store_null(); |
| 3488 | 71235 | return protocol->store_short(Field_short::val_int(), | |
| 3489 |
2/2✓ Branch 0 taken 9371 times.
✓ Branch 1 taken 61864 times.
|
142470 | zerofill ? field_length : 0); |
| 3490 | } | ||
| 3491 | |||
| 3492 | 2537 | int Field_short::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 3493 | short a, b; | ||
| 3494 |
2/2✓ Branch 0 taken 2513 times.
✓ Branch 1 taken 24 times.
|
2537 | if (table->s->db_low_byte_first) { |
| 3495 | 2513 | a = sint2korr(a_ptr); | |
| 3496 | 2513 | b = sint2korr(b_ptr); | |
| 3497 | } else { | ||
| 3498 | 24 | a = shortget(a_ptr); | |
| 3499 | 24 | b = shortget(b_ptr); | |
| 3500 | } | ||
| 3501 | |||
| 3502 |
2/2✓ Branch 0 taken 1126 times.
✓ Branch 1 taken 1411 times.
|
2537 | if (is_unsigned()) |
| 3503 | 1126 | return ((unsigned short)a < (unsigned short)b) | |
| 3504 |
2/2✓ Branch 0 taken 450 times.
✓ Branch 1 taken 676 times.
|
1576 | ? -1 |
| 3505 |
2/2✓ Branch 0 taken 126 times.
✓ Branch 1 taken 324 times.
|
1576 | : ((unsigned short)a > (unsigned short)b) ? 1 : 0; |
| 3506 |
4/4✓ Branch 0 taken 964 times.
✓ Branch 1 taken 447 times.
✓ Branch 2 taken 260 times.
✓ Branch 3 taken 704 times.
|
1411 | return (a < b) ? -1 : (a > b) ? 1 : 0; |
| 3507 | } | ||
| 3508 | |||
| 3509 | 12980 | size_t Field_short::make_sort_key(uchar *to, | |
| 3510 | size_t length [[maybe_unused]]) const { | ||
| 3511 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12980 times.
|
12980 | assert(length == 2); |
| 3512 | #ifdef WORDS_BIGENDIAN | ||
| 3513 | if (!table->s->db_low_byte_first) { | ||
| 3514 | if (is_unsigned()) | ||
| 3515 | to[0] = ptr[0]; | ||
| 3516 | else | ||
| 3517 | to[0] = (char)(ptr[0] ^ 128); /* Revers signbit */ | ||
| 3518 | to[1] = ptr[1]; | ||
| 3519 | } else | ||
| 3520 | #endif | ||
| 3521 | { | ||
| 3522 |
2/2✓ Branch 0 taken 6161 times.
✓ Branch 1 taken 6819 times.
|
12980 | if (is_unsigned()) |
| 3523 | 6161 | to[0] = ptr[1]; | |
| 3524 | else | ||
| 3525 | 6819 | to[0] = (char)(ptr[1] ^ 128); /* Revers signbit */ | |
| 3526 | 12980 | to[1] = ptr[0]; | |
| 3527 | } | ||
| 3528 | 12980 | return 2; | |
| 3529 | } | ||
| 3530 | |||
| 3531 | 91232 | void Field_short::sql_type(String &res) const { | |
| 3532 | 91232 | integer_sql_type(this, "smallint", &res); | |
| 3533 | 91232 | } | |
| 3534 | |||
| 3535 | /**************************************************************************** | ||
| 3536 | Field type medium int (3 byte) | ||
| 3537 | ****************************************************************************/ | ||
| 3538 | |||
| 3539 | 1058 | type_conversion_status Field_medium::store(const char *from, size_t len, | |
| 3540 | const CHARSET_INFO *cs) { | ||
| 3541 |
4/6✓ Branch 0 taken 1058 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 970 times.
✓ Branch 3 taken 88 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 970 times.
|
1058 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3542 | int store_tmp; | ||
| 3543 | longlong rnd; | ||
| 3544 | |||
| 3545 | const type_conversion_status error = | ||
| 3546 |
1/2✓ Branch 0 taken 1058 times.
✗ Branch 1 not taken.
|
1058 | get_int(cs, from, len, &rnd, UINT_MAX24, INT_MIN24, INT_MAX24); |
| 3547 | 1058 | store_tmp = is_unsigned() ? (int)(ulonglong)rnd : (int)rnd; | |
| 3548 | 1058 | int3store(ptr, store_tmp); | |
| 3549 | 1058 | return error; | |
| 3550 | } | ||
| 3551 | |||
| 3552 | 36 | type_conversion_status Field_medium::store(double nr) { | |
| 3553 |
3/6✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 36 times.
|
36 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3554 | 36 | type_conversion_status error = TYPE_OK; | |
| 3555 | 36 | nr = rint(nr); | |
| 3556 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
|
36 | if (is_unsigned()) { |
| 3557 | ✗ | if (nr < 0) { | |
| 3558 | ✗ | int3store(ptr, 0); | |
| 3559 | ✗ | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3560 | ✗ | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3561 | ✗ | } else if (nr >= (double)(long)(1L << 24)) { | |
| 3562 | ✗ | uint32 tmp = (uint32)(1L << 24) - 1L; | |
| 3563 | ✗ | int3store(ptr, tmp); | |
| 3564 | ✗ | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3565 | ✗ | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3566 | } else | ||
| 3567 | ✗ | int3store(ptr, (uint32)nr); | |
| 3568 | } else { | ||
| 3569 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
|
36 | if (nr < INT_MIN24) { |
| 3570 | 18 | long tmp = (long)INT_MIN24; | |
| 3571 | 18 | int3store(ptr, tmp); | |
| 3572 | 18 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3573 | 18 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3574 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | } else if (nr > INT_MAX24) { |
| 3575 | 18 | long tmp = (long)INT_MAX24; | |
| 3576 | 18 | int3store(ptr, tmp); | |
| 3577 | 18 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3578 | 18 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3579 | } else | ||
| 3580 | ✗ | int3store(ptr, (long)nr); | |
| 3581 | } | ||
| 3582 | 36 | return error; | |
| 3583 | } | ||
| 3584 | |||
| 3585 | 591132 | type_conversion_status Field_medium::store(longlong nr, bool unsigned_val) { | |
| 3586 |
4/6✓ Branch 0 taken 591132 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 591040 times.
✓ Branch 3 taken 92 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 591040 times.
|
591132 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3587 | 591132 | type_conversion_status error = TYPE_OK; | |
| 3588 | |||
| 3589 |
2/2✓ Branch 0 taken 265676 times.
✓ Branch 1 taken 325456 times.
|
591132 | if (is_unsigned()) { |
| 3590 |
4/4✓ Branch 0 taken 59 times.
✓ Branch 1 taken 265617 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 11 times.
|
265676 | if (nr < 0 && !unsigned_val) { |
| 3591 | 48 | int3store(ptr, 0); | |
| 3592 | 48 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3593 | 48 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3594 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 265594 times.
|
265628 | } else if ((ulonglong)nr >= (ulonglong)(long)(1L << 24)) { |
| 3595 | 34 | long tmp = (long)(1L << 24) - 1L; | |
| 3596 | 34 | int3store(ptr, tmp); | |
| 3597 | 34 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3598 | 34 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3599 | } else | ||
| 3600 | 265594 | int3store(ptr, (uint32)nr); | |
| 3601 | } else { | ||
| 3602 |
4/4✓ Branch 0 taken 587 times.
✓ Branch 1 taken 324869 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 581 times.
|
325456 | if (nr < 0 && unsigned_val) |
| 3603 | 6 | nr = (ulonglong)(long)(1L << 24); // Generate overflow | |
| 3604 | |||
| 3605 |
2/2✓ Branch 0 taken 98 times.
✓ Branch 1 taken 325358 times.
|
325456 | if (nr < (longlong)INT_MIN24) { |
| 3606 | 98 | long tmp = (long)INT_MIN24; | |
| 3607 | 98 | int3store(ptr, tmp); | |
| 3608 | 98 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3609 | 98 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3610 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 325246 times.
|
325358 | } else if (nr > (longlong)INT_MAX24) { |
| 3611 | 112 | long tmp = (long)INT_MAX24; | |
| 3612 | 112 | int3store(ptr, tmp); | |
| 3613 | 112 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3614 | 112 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3615 | } else | ||
| 3616 | 325246 | int3store(ptr, (long)nr); | |
| 3617 | } | ||
| 3618 | 591132 | return error; | |
| 3619 | } | ||
| 3620 | |||
| 3621 | 36 | double Field_medium::val_real() const { | |
| 3622 |
3/6✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 36 times.
|
36 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3623 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
|
36 | long j = is_unsigned() ? (long)uint3korr(ptr) : sint3korr(ptr); |
| 3624 | 36 | return (double)j; | |
| 3625 | } | ||
| 3626 | |||
| 3627 | 1319397 | longlong Field_medium::val_int() const { | |
| 3628 |
4/6✓ Branch 0 taken 1319397 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1319393 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1319393 times.
|
1319397 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3629 |
2/2✓ Branch 0 taken 537811 times.
✓ Branch 1 taken 781586 times.
|
1319397 | long j = is_unsigned() ? (long)uint3korr(ptr) : sint3korr(ptr); |
| 3630 | 1319397 | return (longlong)j; | |
| 3631 | } | ||
| 3632 | |||
| 3633 | 808 | String *Field_medium::val_str(String *val_buffer, String *) const { | |
| 3634 |
4/6✓ Branch 0 taken 808 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 660 times.
✓ Branch 3 taken 148 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 660 times.
|
808 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3635 | 808 | const CHARSET_INFO *cs = &my_charset_numeric; | |
| 3636 | uint length; | ||
| 3637 | 808 | uint mlength = max(field_length + 1, 10 * cs->mbmaxlen); | |
| 3638 | 808 | val_buffer->alloc(mlength); | |
| 3639 | 808 | char *to = val_buffer->ptr(); | |
| 3640 |
2/2✓ Branch 0 taken 228 times.
✓ Branch 1 taken 580 times.
|
808 | long j = is_unsigned() ? (long)uint3korr(ptr) : sint3korr(ptr); |
| 3641 | |||
| 3642 | 808 | length = (uint)cs->cset->long10_to_str(cs, to, mlength, -10, j); | |
| 3643 | 808 | val_buffer->length(length); | |
| 3644 |
2/2✓ Branch 0 taken 104 times.
✓ Branch 1 taken 704 times.
|
808 | if (zerofill) prepend_zeros(val_buffer); /* purecov: inspected */ |
| 3645 | 808 | val_buffer->set_charset(cs); | |
| 3646 | 808 | return val_buffer; | |
| 3647 | } | ||
| 3648 | |||
| 3649 | 40833 | bool Field_medium::send_to_protocol(Protocol *protocol) const { | |
| 3650 |
3/6✓ Branch 0 taken 40833 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40833 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 40833 times.
|
40833 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3651 |
2/2✓ Branch 0 taken 2826 times.
✓ Branch 1 taken 38007 times.
|
40833 | if (is_null()) return protocol->store_null(); |
| 3652 | 38007 | return protocol->store_long(Field_medium::val_int(), | |
| 3653 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 37951 times.
|
76014 | zerofill ? field_length : 0); |
| 3654 | } | ||
| 3655 | |||
| 3656 | 20310 | int Field_medium::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 3657 | long a, b; | ||
| 3658 |
2/2✓ Branch 0 taken 1123 times.
✓ Branch 1 taken 19187 times.
|
20310 | if (is_unsigned()) { |
| 3659 | 1123 | a = uint3korr(a_ptr); | |
| 3660 | 1123 | b = uint3korr(b_ptr); | |
| 3661 | } else { | ||
| 3662 | 19187 | a = sint3korr(a_ptr); | |
| 3663 | 19187 | b = sint3korr(b_ptr); | |
| 3664 | } | ||
| 3665 |
4/4✓ Branch 0 taken 16111 times.
✓ Branch 1 taken 4199 times.
✓ Branch 2 taken 861 times.
✓ Branch 3 taken 15250 times.
|
20310 | return (a < b) ? -1 : (a > b) ? 1 : 0; |
| 3666 | } | ||
| 3667 | |||
| 3668 | 575377 | size_t Field_medium::make_sort_key(uchar *to, | |
| 3669 | size_t length [[maybe_unused]]) const { | ||
| 3670 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 575377 times.
|
575377 | assert(length == 3); |
| 3671 |
2/2✓ Branch 0 taken 263570 times.
✓ Branch 1 taken 311807 times.
|
575377 | if (is_unsigned()) |
| 3672 | 263570 | to[0] = ptr[2]; | |
| 3673 | else | ||
| 3674 | 311807 | to[0] = (uchar)(ptr[2] ^ 128); /* Revers signbit */ | |
| 3675 | 575377 | to[1] = ptr[1]; | |
| 3676 | 575377 | to[2] = ptr[0]; | |
| 3677 | 575377 | return 3; | |
| 3678 | } | ||
| 3679 | |||
| 3680 | 41958 | void Field_medium::sql_type(String &res) const { | |
| 3681 | 41958 | integer_sql_type(this, "mediumint", &res); | |
| 3682 | 41958 | } | |
| 3683 | |||
| 3684 | /**************************************************************************** | ||
| 3685 | ** long int | ||
| 3686 | ****************************************************************************/ | ||
| 3687 | |||
| 3688 | 44948203 | type_conversion_status Field_long::store(const char *from, size_t len, | |
| 3689 | const CHARSET_INFO *cs) { | ||
| 3690 |
4/6✓ Branch 0 taken 44957047 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44939429 times.
✓ Branch 3 taken 17618 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 44940671 times.
|
44948203 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3691 | long store_tmp; | ||
| 3692 | longlong rnd; | ||
| 3693 | |||
| 3694 | const type_conversion_status error = | ||
| 3695 |
1/2✓ Branch 0 taken 44961947 times.
✗ Branch 1 not taken.
|
44949445 | get_int(cs, from, len, &rnd, UINT_MAX32, INT_MIN32, INT_MAX32); |
| 3696 | 44961947 | store_tmp = is_unsigned() ? (long)(ulonglong)rnd : (long)rnd; | |
| 3697 |
1/2✓ Branch 0 taken 44970441 times.
✗ Branch 1 not taken.
|
44970012 | if (table->s->db_low_byte_first) |
| 3698 | 44970441 | int4store(ptr, store_tmp); | |
| 3699 | else | ||
| 3700 | ✗ | longstore(ptr, store_tmp); | |
| 3701 | 44968922 | return error; | |
| 3702 | } | ||
| 3703 | |||
| 3704 | 3730484 | type_conversion_status Field_long::store(double nr) { | |
| 3705 |
4/6✓ Branch 0 taken 3730485 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3728962 times.
✓ Branch 3 taken 1523 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3728964 times.
|
3730484 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3706 | 3730486 | type_conversion_status error = TYPE_OK; | |
| 3707 | int32 res; | ||
| 3708 | 3730486 | nr = rint(nr); | |
| 3709 |
2/2✓ Branch 0 taken 9188 times.
✓ Branch 1 taken 3721299 times.
|
3730486 | if (is_unsigned()) { |
| 3710 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9188 times.
|
9188 | if (nr < 0) { |
| 3711 | ✗ | res = 0; | |
| 3712 | ✗ | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3713 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9188 times.
|
9188 | } else if (nr > UINT_MAX32) { |
| 3714 | ✗ | res = UINT_MAX32; | |
| 3715 | ✗ | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3716 | ✗ | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3717 | } else | ||
| 3718 | 9188 | res = (int32)(ulong)nr; | |
| 3719 | } else { | ||
| 3720 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 3721259 times.
|
3721299 | if (nr < INT_MIN32) { |
| 3721 | 40 | res = (int32)INT_MIN32; | |
| 3722 | 40 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3723 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 3721223 times.
|
3721259 | } else if (nr > INT_MAX32) { |
| 3724 | 36 | res = (int32)INT_MAX32; | |
| 3725 | 36 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3726 | } else | ||
| 3727 | 3721223 | res = (int32)(longlong)nr; | |
| 3728 | } | ||
| 3729 |
2/2✓ Branch 0 taken 76 times.
✓ Branch 1 taken 3730411 times.
|
3730487 | if (error) |
| 3730 | 76 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3731 | |||
| 3732 |
2/2✓ Branch 0 taken 3728961 times.
✓ Branch 1 taken 1523 times.
|
3730484 | if (table->s->db_low_byte_first) |
| 3733 | 3728961 | int4store(ptr, res); | |
| 3734 | else | ||
| 3735 | 1523 | longstore(ptr, res); | |
| 3736 | 3730484 | return error; | |
| 3737 | } | ||
| 3738 | |||
| 3739 | /** | ||
| 3740 | Store a longlong in the field | ||
| 3741 | |||
| 3742 | @param nr the value to store | ||
| 3743 | @param unsigned_val whether or not 'nr' should be interpreted as | ||
| 3744 | signed or unsigned. E.g., if 'nr' has all bits | ||
| 3745 | set it is interpreted as -1 if unsigned_val is | ||
| 3746 | false and ULLONG_MAX if unsigned_val is true. | ||
| 3747 | */ | ||
| 3748 | 131087339 | type_conversion_status Field_long::store(longlong nr, bool unsigned_val) { | |
| 3749 |
4/6✓ Branch 0 taken 131089592 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130862029 times.
✓ Branch 3 taken 227563 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 130862216 times.
|
131087339 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3750 | 131087526 | type_conversion_status error = TYPE_OK; | |
| 3751 | int32 res; | ||
| 3752 | |||
| 3753 |
2/2✓ Branch 0 taken 51094477 times.
✓ Branch 1 taken 79996101 times.
|
131087526 | if (is_unsigned()) { |
| 3754 |
4/4✓ Branch 0 taken 106 times.
✓ Branch 1 taken 51094371 times.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 16 times.
|
51094477 | if (nr < 0 && !unsigned_val) { |
| 3755 | 90 | res = 0; | |
| 3756 | 90 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3757 |
2/2✓ Branch 0 taken 54 times.
✓ Branch 1 taken 51094333 times.
|
51094387 | } else if ((ulonglong)nr >= (1LL << 32)) { |
| 3758 | 54 | res = (int32)(uint32)~0L; | |
| 3759 | 54 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3760 | } else | ||
| 3761 | 51094333 | res = (int32)(uint32)nr; | |
| 3762 | } else { | ||
| 3763 |
4/4✓ Branch 0 taken 56458 times.
✓ Branch 1 taken 79939643 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 56446 times.
|
79996101 | if (nr < 0 && unsigned_val) { |
| 3764 | 12 | nr = ((longlong)INT_MAX32) + 1; // Generate overflow | |
| 3765 | 12 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3766 | } | ||
| 3767 |
2/2✓ Branch 0 taken 149 times.
✓ Branch 1 taken 79995952 times.
|
79996101 | if (nr < (longlong)INT_MIN32) { |
| 3768 | 149 | res = (int32)INT_MIN32; | |
| 3769 | 149 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3770 |
2/2✓ Branch 0 taken 327 times.
✓ Branch 1 taken 79995625 times.
|
79995952 | } else if (nr > (longlong)INT_MAX32) { |
| 3771 | 327 | res = (int32)INT_MAX32; | |
| 3772 | 327 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3773 | } else | ||
| 3774 | 79995625 | res = (int32)nr; | |
| 3775 | } | ||
| 3776 |
2/2✓ Branch 0 taken 620 times.
✓ Branch 1 taken 131089958 times.
|
131090578 | if (error) |
| 3777 | 620 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3778 | |||
| 3779 |
2/2✓ Branch 0 taken 130879872 times.
✓ Branch 1 taken 210412 times.
|
131090284 | if (table->s->db_low_byte_first) |
| 3780 | 130879872 | int4store(ptr, res); | |
| 3781 | else | ||
| 3782 | 210412 | longstore(ptr, res); | |
| 3783 | 131091624 | return error; | |
| 3784 | } | ||
| 3785 | |||
| 3786 | 447314 | double Field_long::val_real() const { | |
| 3787 |
4/6✓ Branch 0 taken 447314 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 447303 times.
✓ Branch 3 taken 11 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 447303 times.
|
447314 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3788 | int32 j; | ||
| 3789 |
2/2✓ Branch 0 taken 447303 times.
✓ Branch 1 taken 11 times.
|
447314 | if (table->s->db_low_byte_first) |
| 3790 | 447303 | j = sint4korr(ptr); | |
| 3791 | else | ||
| 3792 | 11 | j = longget(ptr); | |
| 3793 |
2/2✓ Branch 0 taken 39856 times.
✓ Branch 1 taken 407457 times.
|
447313 | return is_unsigned() ? (double)(uint32)j : (double)j; |
| 3794 | } | ||
| 3795 | |||
| 3796 | 481075329 | longlong Field_long::val_int() const { | |
| 3797 |
4/6✓ Branch 0 taken 481101083 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 480905981 times.
✓ Branch 3 taken 195102 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 480954141 times.
|
481075329 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3798 | int32 j; | ||
| 3799 |
2/2✓ Branch 0 taken 480913176 times.
✓ Branch 1 taken 210313 times.
|
481123489 | if (table->s->db_low_byte_first) |
| 3800 | 480913176 | j = sint4korr(ptr); | |
| 3801 | else | ||
| 3802 | 210313 | j = longget(ptr); | |
| 3803 |
2/2✓ Branch 0 taken 257954928 times.
✓ Branch 1 taken 223183776 times.
|
481129297 | return is_unsigned() ? (longlong)(uint32)j : (longlong)j; |
| 3804 | } | ||
| 3805 | |||
| 3806 | 9275274 | String *Field_long::val_str(String *val_buffer, String *) const { | |
| 3807 |
4/6✓ Branch 0 taken 9275299 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9224460 times.
✓ Branch 3 taken 50839 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9224509 times.
|
9275274 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3808 | 9275323 | const CHARSET_INFO *cs = &my_charset_numeric; | |
| 3809 | size_t length; | ||
| 3810 | 9275323 | uint mlength = max(field_length + 1, 12 * cs->mbmaxlen); | |
| 3811 | 9275376 | val_buffer->alloc(mlength); | |
| 3812 | 9275438 | char *to = val_buffer->ptr(); | |
| 3813 | int32 j; | ||
| 3814 |
2/2✓ Branch 0 taken 9273802 times.
✓ Branch 1 taken 1637 times.
|
9275439 | if (table->s->db_low_byte_first) |
| 3815 | 9273802 | j = sint4korr(ptr); | |
| 3816 | else | ||
| 3817 | 1637 | j = longget(ptr); | |
| 3818 | |||
| 3819 |
2/2✓ Branch 0 taken 730064 times.
✓ Branch 1 taken 8545373 times.
|
9275442 | if (is_unsigned()) |
| 3820 | 730064 | length = cs->cset->long10_to_str(cs, to, mlength, 10, (long)(uint32)j); | |
| 3821 | else | ||
| 3822 | 8545373 | length = cs->cset->long10_to_str(cs, to, mlength, -10, (long)j); | |
| 3823 | 9275412 | val_buffer->length(length); | |
| 3824 |
2/2✓ Branch 0 taken 75706 times.
✓ Branch 1 taken 9199713 times.
|
9275419 | if (zerofill) prepend_zeros(val_buffer); |
| 3825 | 9275419 | val_buffer->set_charset(cs); | |
| 3826 | 9275430 | return val_buffer; | |
| 3827 | } | ||
| 3828 | |||
| 3829 | 43460362 | bool Field_long::send_to_protocol(Protocol *protocol) const { | |
| 3830 |
3/6✓ Branch 0 taken 43460729 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43460985 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 43461009 times.
|
43460362 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3831 |
2/2✓ Branch 0 taken 5519214 times.
✓ Branch 1 taken 37941829 times.
|
43460386 | if (is_null()) return protocol->store_null(); |
| 3832 | 37941829 | return protocol->store_long(Field_long::val_int(), | |
| 3833 |
2/2✓ Branch 0 taken 15704 times.
✓ Branch 1 taken 37926125 times.
|
75883533 | zerofill ? field_length : 0); |
| 3834 | } | ||
| 3835 | |||
| 3836 | 4765808 | int Field_long::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 3837 | int32 a, b; | ||
| 3838 |
1/2✓ Branch 0 taken 4765817 times.
✗ Branch 1 not taken.
|
4765808 | if (table->s->db_low_byte_first) { |
| 3839 | 4765817 | a = sint4korr(a_ptr); | |
| 3840 | 4765841 | b = sint4korr(b_ptr); | |
| 3841 | } else { | ||
| 3842 | ✗ | a = longget(a_ptr); | |
| 3843 | ✗ | b = longget(b_ptr); | |
| 3844 | } | ||
| 3845 |
2/2✓ Branch 0 taken 727373 times.
✓ Branch 1 taken 4038499 times.
|
4765864 | if (is_unsigned()) |
| 3846 |
4/4✓ Branch 0 taken 423835 times.
✓ Branch 1 taken 303538 times.
✓ Branch 2 taken 61803 times.
✓ Branch 3 taken 362032 times.
|
727373 | return ((uint32)a < (uint32)b) ? -1 : ((uint32)a > (uint32)b) ? 1 : 0; |
| 3847 |
4/4✓ Branch 0 taken 2431729 times.
✓ Branch 1 taken 1606770 times.
✓ Branch 2 taken 296919 times.
✓ Branch 3 taken 2134810 times.
|
4038499 | return (a < b) ? -1 : (a > b) ? 1 : 0; |
| 3848 | } | ||
| 3849 | |||
| 3850 | 44697713 | size_t Field_long::make_sort_key(uchar *to, | |
| 3851 | size_t length [[maybe_unused]]) const { | ||
| 3852 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44697713 times.
|
44697713 | assert(length == 4); |
| 3853 | #ifdef WORDS_BIGENDIAN | ||
| 3854 | if (!table->s->db_low_byte_first) { | ||
| 3855 | if (is_unsigned()) | ||
| 3856 | to[0] = ptr[0]; | ||
| 3857 | else | ||
| 3858 | to[0] = (char)(ptr[0] ^ 128); /* Reverse sign bit */ | ||
| 3859 | to[1] = ptr[1]; | ||
| 3860 | to[2] = ptr[2]; | ||
| 3861 | to[3] = ptr[3]; | ||
| 3862 | } else | ||
| 3863 | #endif | ||
| 3864 | { | ||
| 3865 |
2/2✓ Branch 0 taken 1360132 times.
✓ Branch 1 taken 43360235 times.
|
44697713 | if (is_unsigned()) |
| 3866 | 1360132 | to[0] = ptr[3]; | |
| 3867 | else | ||
| 3868 | 43360235 | to[0] = (char)(ptr[3] ^ 128); /* Reverse sign bit */ | |
| 3869 | 44720367 | to[1] = ptr[2]; | |
| 3870 | 44720367 | to[2] = ptr[1]; | |
| 3871 | 44720367 | to[3] = ptr[0]; | |
| 3872 | } | ||
| 3873 | 44720367 | return 4; | |
| 3874 | } | ||
| 3875 | |||
| 3876 | 1774843 | void Field_long::sql_type(String &res) const { | |
| 3877 | 1774843 | integer_sql_type(this, "int", &res); | |
| 3878 | 1774885 | } | |
| 3879 | |||
| 3880 | /**************************************************************************** | ||
| 3881 | Field type longlong int (8 bytes) | ||
| 3882 | ****************************************************************************/ | ||
| 3883 | |||
| 3884 | 2051089 | type_conversion_status Field_longlong::store(const char *from, size_t len, | |
| 3885 | const CHARSET_INFO *cs) { | ||
| 3886 |
4/6✓ Branch 0 taken 2051089 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1919393 times.
✓ Branch 3 taken 131696 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1919393 times.
|
2051089 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3887 | 2051089 | int conv_err = 0; | |
| 3888 | 2051089 | type_conversion_status error = TYPE_OK; | |
| 3889 | const char *end; | ||
| 3890 | ulonglong tmp; | ||
| 3891 | |||
| 3892 |
1/2✓ Branch 0 taken 2051091 times.
✗ Branch 1 not taken.
|
2051089 | tmp = cs->cset->strntoull10rnd(cs, from, len, is_unsigned(), &end, &conv_err); |
| 3893 |
2/2✓ Branch 0 taken 151 times.
✓ Branch 1 taken 2050940 times.
|
2051091 | if (conv_err == MY_ERRNO_ERANGE) { |
| 3894 |
1/2✓ Branch 0 taken 151 times.
✗ Branch 1 not taken.
|
151 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); |
| 3895 | 151 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3896 |
5/6✓ Branch 0 taken 2050944 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136887 times.
✓ Branch 3 taken 1914057 times.
✓ Branch 4 taken 57 times.
✓ Branch 5 taken 2050887 times.
|
2187827 | } else if (current_thd->check_for_truncated_fields && |
| 3897 |
3/4✓ Branch 0 taken 136887 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✓ Branch 3 taken 136830 times.
|
136887 | check_int(cs, from, len, end, conv_err)) |
| 3898 | 57 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3899 | else | ||
| 3900 | 2050887 | error = TYPE_OK; | |
| 3901 | |||
| 3902 |
2/2✓ Branch 0 taken 2051089 times.
✓ Branch 1 taken 6 times.
|
2051095 | if (table->s->db_low_byte_first) |
| 3903 | 2051089 | int8store(ptr, tmp); | |
| 3904 | else | ||
| 3905 | 6 | longlongstore(ptr, tmp); | |
| 3906 | 2051094 | return error; | |
| 3907 | } | ||
| 3908 | |||
| 3909 | 3652321 | type_conversion_status Field_longlong::store(double nr) { | |
| 3910 |
3/6✓ Branch 0 taken 3652321 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3652321 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3652321 times.
|
3652321 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3911 | 3652321 | type_conversion_status error = TYPE_OK; | |
| 3912 | longlong res; | ||
| 3913 | |||
| 3914 | 3652321 | nr = rint(nr); | |
| 3915 |
2/2✓ Branch 0 taken 642119 times.
✓ Branch 1 taken 3010202 times.
|
3652321 | if (is_unsigned()) { |
| 3916 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 642115 times.
|
642119 | if (nr < 0) { |
| 3917 | 4 | res = 0; | |
| 3918 | 4 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3919 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 642115 times.
|
642115 | } else if (nr >= ULLONG_MAX_DOUBLE) { |
| 3920 | ✗ | res = ~(longlong)0; | |
| 3921 | ✗ | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3922 | } else | ||
| 3923 | 642115 | res = double2ulonglong(nr); | |
| 3924 | } else { | ||
| 3925 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3010184 times.
|
3010202 | if (nr <= LLONG_MIN) { |
| 3926 | 18 | res = LLONG_MIN; | |
| 3927 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | if (nr < LLONG_MIN) error = TYPE_WARN_OUT_OF_RANGE; |
| 3928 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3010166 times.
|
3010184 | } else if (nr >= LLONG_MAX_DOUBLE) { |
| 3929 | 18 | res = LLONG_MAX; | |
| 3930 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | if (nr > LLONG_MAX_DOUBLE) error = TYPE_WARN_OUT_OF_RANGE; |
| 3931 | } else | ||
| 3932 | 3010166 | res = nr; | |
| 3933 | } | ||
| 3934 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 3652281 times.
|
3652321 | if (error) |
| 3935 | 40 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3936 | |||
| 3937 |
1/2✓ Branch 0 taken 3652321 times.
✗ Branch 1 not taken.
|
3652321 | if (table->s->db_low_byte_first) |
| 3938 | 3652321 | int8store(ptr, res); | |
| 3939 | else | ||
| 3940 | ✗ | longlongstore(ptr, res); | |
| 3941 | 3652321 | return error; | |
| 3942 | } | ||
| 3943 | |||
| 3944 | 240603060 | type_conversion_status Field_longlong::store(longlong nr, bool unsigned_val) { | |
| 3945 |
4/6✓ Branch 0 taken 240603114 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 240600769 times.
✓ Branch 3 taken 2345 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 240600798 times.
|
240603060 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 3946 | 240603089 | type_conversion_status error = TYPE_OK; | |
| 3947 | |||
| 3948 |
2/2✓ Branch 0 taken 758369 times.
✓ Branch 1 taken 239844720 times.
|
240603089 | if (nr < 0) // Only possible error |
| 3949 | { | ||
| 3950 | /* | ||
| 3951 | if field is unsigned and value is signed (< 0) or | ||
| 3952 | if field is signed and value is unsigned we have an overflow | ||
| 3953 | */ | ||
| 3954 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 758289 times.
|
758369 | if (is_unsigned() != unsigned_val) { |
| 3955 |
2/2✓ Branch 0 taken 235 times.
✓ Branch 1 taken 45 times.
|
93 | nr = is_unsigned() ? (ulonglong)0 : (ulonglong)LLONG_MAX; |
| 3956 | 280 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 3957 | 280 | error = TYPE_WARN_OUT_OF_RANGE; | |
| 3958 | } | ||
| 3959 | } | ||
| 3960 | |||
| 3961 |
2/2✓ Branch 0 taken 240602051 times.
✓ Branch 1 taken 1238 times.
|
240603289 | if (table->s->db_low_byte_first) |
| 3962 | 240602051 | int8store(ptr, nr); | |
| 3963 | else | ||
| 3964 | 1238 | longlongstore(ptr, nr); | |
| 3965 | 240603261 | return error; | |
| 3966 | } | ||
| 3967 | |||
| 3968 | 31290 | double Field_longlong::val_real() const { | |
| 3969 |
3/6✓ Branch 0 taken 31290 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31291 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 31291 times.
|
31290 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3970 | longlong j; | ||
| 3971 |
1/2✓ Branch 0 taken 31290 times.
✗ Branch 1 not taken.
|
31290 | if (table->s->db_low_byte_first) |
| 3972 | 31290 | j = sint8korr(ptr); | |
| 3973 | else | ||
| 3974 | ✗ | j = longlongget(ptr); | |
| 3975 |
2/2✓ Branch 0 taken 21421 times.
✓ Branch 1 taken 9870 times.
|
31290 | if (is_unsigned()) { |
| 3976 | 21421 | return ulonglong2double(static_cast<ulonglong>(j)); | |
| 3977 | } | ||
| 3978 | 9870 | return static_cast<double>(j); | |
| 3979 | } | ||
| 3980 | |||
| 3981 | 401442369 | longlong Field_longlong::val_int() const { | |
| 3982 |
4/6✓ Branch 0 taken 401442534 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 401441416 times.
✓ Branch 3 taken 1118 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 401441736 times.
|
401442369 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 3983 |
2/2✓ Branch 0 taken 401441443 times.
✓ Branch 1 taken 1246 times.
|
401442689 | if (table->s->db_low_byte_first) |
| 3984 | 401441443 | return sint8korr(ptr); | |
| 3985 | else | ||
| 3986 | 1246 | return longlongget(ptr); | |
| 3987 | } | ||
| 3988 | |||
| 3989 | 714164 | String *Field_longlong::val_str(String *val_buffer, String *) const { | |
| 3990 | 714164 | const CHARSET_INFO *cs = &my_charset_numeric; | |
| 3991 | uint length; | ||
| 3992 | 714164 | uint mlength = max(field_length + 1, 22 * cs->mbmaxlen); | |
| 3993 | 714164 | val_buffer->alloc(mlength); | |
| 3994 | 714164 | char *to = val_buffer->ptr(); | |
| 3995 | longlong j; | ||
| 3996 |
1/2✓ Branch 0 taken 714164 times.
✗ Branch 1 not taken.
|
714164 | if (table->s->db_low_byte_first) |
| 3997 | 714164 | j = sint8korr(ptr); | |
| 3998 | else | ||
| 3999 | ✗ | j = longlongget(ptr); | |
| 4000 | |||
| 4001 |
2/2✓ Branch 0 taken 544181 times.
✓ Branch 1 taken 169983 times.
|
714164 | length = (uint)(cs->cset->longlong10_to_str)(cs, to, mlength, |
| 4002 | 714164 | is_unsigned() ? 10 : -10, j); | |
| 4003 | 714164 | val_buffer->length(length); | |
| 4004 |
2/2✓ Branch 0 taken 104 times.
✓ Branch 1 taken 714060 times.
|
714164 | if (zerofill) prepend_zeros(val_buffer); |
| 4005 | 714164 | val_buffer->set_charset(cs); | |
| 4006 | 714164 | return val_buffer; | |
| 4007 | } | ||
| 4008 | |||
| 4009 | 99520282 | bool Field_longlong::send_to_protocol(Protocol *protocol) const { | |
| 4010 |
3/6✓ Branch 0 taken 99520282 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 99520282 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 99520282 times.
|
99520282 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4011 |
2/2✓ Branch 0 taken 20625214 times.
✓ Branch 1 taken 78895068 times.
|
99520282 | if (is_null()) return protocol->store_null(); |
| 4012 | 78895068 | return protocol->store_longlong(Field_longlong::val_int(), is_unsigned(), | |
| 4013 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 78895012 times.
|
157790136 | zerofill ? field_length : 0); |
| 4014 | } | ||
| 4015 | |||
| 4016 | 601002 | int Field_longlong::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 4017 | longlong a, b; | ||
| 4018 |
1/2✓ Branch 0 taken 601003 times.
✗ Branch 1 not taken.
|
601002 | if (table->s->db_low_byte_first) { |
| 4019 | 601003 | a = sint8korr(a_ptr); | |
| 4020 | 601003 | b = sint8korr(b_ptr); | |
| 4021 | } else { | ||
| 4022 | ✗ | a = longlongget(a_ptr); | |
| 4023 | ✗ | b = longlongget(b_ptr); | |
| 4024 | } | ||
| 4025 |
2/2✓ Branch 0 taken 95601 times.
✓ Branch 1 taken 505402 times.
|
601003 | if (is_unsigned()) |
| 4026 | 95601 | return ((ulonglong)a < (ulonglong)b) | |
| 4027 |
2/2✓ Branch 0 taken 46822 times.
✓ Branch 1 taken 48779 times.
|
142423 | ? -1 |
| 4028 |
2/2✓ Branch 0 taken 2015 times.
✓ Branch 1 taken 44807 times.
|
142423 | : ((ulonglong)a > (ulonglong)b) ? 1 : 0; |
| 4029 |
4/4✓ Branch 0 taken 329041 times.
✓ Branch 1 taken 176361 times.
✓ Branch 2 taken 324045 times.
✓ Branch 3 taken 4996 times.
|
505402 | return (a < b) ? -1 : (a > b) ? 1 : 0; |
| 4030 | } | ||
| 4031 | |||
| 4032 | 4363327 | size_t Field_longlong::make_sort_key(uchar *to, size_t length) const { | |
| 4033 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4363327 times.
|
4363327 | assert(length == PACK_LENGTH); |
| 4034 | #ifdef WORDS_BIGENDIAN | ||
| 4035 | if (table == NULL || !table->s->db_low_byte_first) | ||
| 4036 | copy_integer<true>(to, length, ptr, PACK_LENGTH, is_unsigned()); | ||
| 4037 | else | ||
| 4038 | #endif | ||
| 4039 | 4363327 | copy_integer<false>(to, length, ptr, PACK_LENGTH, is_unsigned()); | |
| 4040 | 4363911 | return PACK_LENGTH; | |
| 4041 | } | ||
| 4042 | |||
| 4043 | 2847389 | void Field_longlong::sql_type(String &res) const { | |
| 4044 | 2847389 | integer_sql_type(this, "bigint", &res); | |
| 4045 | 2847389 | } | |
| 4046 | |||
| 4047 | /* | ||
| 4048 | Floating-point numbers | ||
| 4049 | */ | ||
| 4050 | |||
| 4051 | 1699287 | uchar *Field_real::pack(uchar *to, const uchar *from, size_t max_length) const { | |
| 4052 |
1/2✓ Branch 0 taken 1699290 times.
✗ Branch 1 not taken.
|
1699287 | DBUG_TRACE; |
| 4053 | #ifdef WORDS_BIGENDIAN | ||
| 4054 | if (!table->s->db_low_byte_first) { | ||
| 4055 | size_t len = std::min<size_t>(pack_length(), max_length); | ||
| 4056 | for (size_t i = 0; i < len; ++i) { | ||
| 4057 | to[i] = from[pack_length() - i - 1]; | ||
| 4058 | } | ||
| 4059 | return to + pack_length(); | ||
| 4060 | } else | ||
| 4061 | #endif | ||
| 4062 |
1/2✓ Branch 0 taken 1699288 times.
✗ Branch 1 not taken.
|
3398580 | return Field::pack(to, from, max_length); |
| 4063 | 1699288 | } | |
| 4064 | |||
| 4065 | 171833 | const uchar *Field_real::unpack(uchar *to, const uchar *from, uint param_data) { | |
| 4066 |
1/2✓ Branch 0 taken 171833 times.
✗ Branch 1 not taken.
|
171833 | DBUG_TRACE; |
| 4067 | #ifdef WORDS_BIGENDIAN | ||
| 4068 | if (!table->s->db_low_byte_first) { | ||
| 4069 | const uchar *dptr = from + pack_length(); | ||
| 4070 | while (dptr-- > from) *to++ = *dptr; | ||
| 4071 | return from + pack_length(); | ||
| 4072 | } else | ||
| 4073 | #endif | ||
| 4074 |
1/2✓ Branch 0 taken 171833 times.
✗ Branch 1 not taken.
|
343666 | return Field::unpack(to, from, param_data); |
| 4075 | 171833 | } | |
| 4076 | |||
| 4077 | 2 | type_conversion_status Field_real::store_time(MYSQL_TIME *ltime, uint8) { | |
| 4078 | 2 | double nr = TIME_to_double(*ltime); | |
| 4079 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | return store(ltime->neg ? -nr : nr); |
| 4080 | } | ||
| 4081 | |||
| 4082 | /**************************************************************************** | ||
| 4083 | single precision float | ||
| 4084 | ****************************************************************************/ | ||
| 4085 | |||
| 4086 | 52602 | type_conversion_status Field_float::store(const char *from, size_t len, | |
| 4087 | const CHARSET_INFO *cs) { | ||
| 4088 |
1/2✓ Branch 0 taken 52602 times.
✗ Branch 1 not taken.
|
52602 | THD *thd = current_thd; |
| 4089 | |||
| 4090 | int conv_error; | ||
| 4091 | 52602 | type_conversion_status err = TYPE_OK; | |
| 4092 | const char *end; | ||
| 4093 |
1/2✓ Branch 0 taken 52602 times.
✗ Branch 1 not taken.
|
52602 | double nr = my_strntod(cs, from, len, &end, &conv_error); |
| 4094 |
6/6✓ Branch 0 taken 52587 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 52571 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 44 times.
✓ Branch 5 taken 52558 times.
|
105173 | if (conv_error != 0 || end == from || |
| 4095 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 52556 times.
|
52571 | (((uint)(end - from) != len && |
| 4096 |
3/4✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 2 times.
|
15 | !check_if_only_end_space(cs, end, from + len) && |
| 4097 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | thd->check_for_truncated_fields))) { |
| 4098 |
1/2✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 | set_warning(Sql_condition::SL_WARNING, |
| 4099 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 29 times.
|
44 | (conv_error ? ER_WARN_DATA_OUT_OF_RANGE : WARN_DATA_TRUNCATED), |
| 4100 | 1); | ||
| 4101 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 29 times.
|
44 | err = conv_error ? TYPE_WARN_OUT_OF_RANGE : TYPE_WARN_TRUNCATED; |
| 4102 | } | ||
| 4103 |
1/2✓ Branch 0 taken 52602 times.
✗ Branch 1 not taken.
|
52602 | Field_float::store(nr); |
| 4104 | 52602 | return err; | |
| 4105 | } | ||
| 4106 | |||
| 4107 | 960270 | type_conversion_status Field_float::store(double nr) { | |
| 4108 |
4/6✓ Branch 0 taken 960270 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 958121 times.
✓ Branch 3 taken 2149 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 958121 times.
|
960270 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 4109 | const type_conversion_status error = | ||
| 4110 |
2/2✓ Branch 0 taken 250 times.
✓ Branch 1 taken 960020 times.
|
960270 | truncate(&nr, FLT_MAX) ? TYPE_WARN_OUT_OF_RANGE : TYPE_OK; |
| 4111 | |||
| 4112 | 960270 | float j = (float)nr; | |
| 4113 | |||
| 4114 |
2/2✓ Branch 0 taken 960230 times.
✓ Branch 1 taken 40 times.
|
960270 | if (table->s->db_low_byte_first) |
| 4115 | 960230 | float4store(ptr, j); | |
| 4116 | else | ||
| 4117 | 40 | floatstore(ptr, j); | |
| 4118 | 960270 | return error; | |
| 4119 | } | ||
| 4120 | |||
| 4121 | 5050 | type_conversion_status Field_float::store(longlong nr, bool unsigned_val) { | |
| 4122 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 5035 times.
|
5050 | return Field_float::store(unsigned_val ? ulonglong2double((ulonglong)nr) |
| 4123 | 5050 | : (double)nr); | |
| 4124 | } | ||
| 4125 | |||
| 4126 | 38859 | double Field_float::val_real() const { | |
| 4127 |
4/6✓ Branch 0 taken 38859 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38832 times.
✓ Branch 3 taken 27 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 38832 times.
|
38859 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4128 |
2/2✓ Branch 0 taken 38832 times.
✓ Branch 1 taken 27 times.
|
38859 | if (table->s->db_low_byte_first) |
| 4129 | 38832 | return double{float4get(ptr)}; | |
| 4130 | else | ||
| 4131 | 27 | return double{floatget(ptr)}; | |
| 4132 | } | ||
| 4133 | |||
| 4134 | 79 | longlong Field_float::val_int() const { | |
| 4135 | float j; | ||
| 4136 |
1/2✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
|
79 | if (table->s->db_low_byte_first) |
| 4137 | 79 | j = float4get(ptr); | |
| 4138 | else | ||
| 4139 | ✗ | j = floatget(ptr); | |
| 4140 | 79 | return (longlong)rint(j); | |
| 4141 | } | ||
| 4142 | |||
| 4143 | 17089 | String *Field_float::val_str(String *val_buffer, String *) const { | |
| 4144 |
4/6✓ Branch 0 taken 17089 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14971 times.
✓ Branch 3 taken 2118 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 14971 times.
|
17089 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4145 |
3/4✓ Branch 0 taken 1779 times.
✓ Branch 1 taken 15310 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1779 times.
|
17089 | assert(!zerofill || field_length <= MAX_FIELD_CHARLENGTH); |
| 4146 | float nr; | ||
| 4147 |
3/4✓ Branch 0 taken 17089 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17079 times.
✓ Branch 3 taken 10 times.
|
17089 | if (table && table->s->db_low_byte_first) |
| 4148 | 17079 | nr = float4get(ptr); | |
| 4149 | else | ||
| 4150 | 10 | nr = floatget(ptr); | |
| 4151 | |||
| 4152 | 17089 | uint to_length = 70; | |
| 4153 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17089 times.
|
17089 | if (val_buffer->alloc(to_length)) { |
| 4154 | ✗ | my_error(ER_OUT_OF_RESOURCES, MYF(0)); | |
| 4155 | ✗ | return val_buffer; | |
| 4156 | } | ||
| 4157 | |||
| 4158 | 17089 | char *to = val_buffer->ptr(); | |
| 4159 | size_t len; | ||
| 4160 | |||
| 4161 |
2/2✓ Branch 0 taken 13795 times.
✓ Branch 1 taken 3294 times.
|
17089 | if (dec >= DECIMAL_NOT_SPECIFIED) |
| 4162 | 13795 | len = my_gcvt(nr, MY_GCVT_ARG_FLOAT, MAX_FLOAT_STR_LENGTH, to, nullptr); | |
| 4163 | else { | ||
| 4164 | /* | ||
| 4165 | We are safe here because the buffer length is 70, and | ||
| 4166 | fabs(float) < 10^39, dec < DECIMAL_NOT_SPECIFIED. So the resulting string | ||
| 4167 | will be not longer than 69 chars + terminating '\0'. | ||
| 4168 | */ | ||
| 4169 | 3294 | len = my_fcvt(nr, dec, to, nullptr); | |
| 4170 | } | ||
| 4171 | 17089 | val_buffer->length((uint)len); | |
| 4172 |
2/2✓ Branch 0 taken 1779 times.
✓ Branch 1 taken 15310 times.
|
17089 | if (zerofill) prepend_zeros(val_buffer); |
| 4173 | 17089 | val_buffer->set_charset(&my_charset_numeric); | |
| 4174 | 17089 | return val_buffer; | |
| 4175 | } | ||
| 4176 | |||
| 4177 | 470 | int Field_float::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 4178 | float a, b; | ||
| 4179 |
1/2✓ Branch 0 taken 470 times.
✗ Branch 1 not taken.
|
470 | if (table->s->db_low_byte_first) { |
| 4180 | 470 | a = float4get(a_ptr); | |
| 4181 | 470 | b = float4get(b_ptr); | |
| 4182 | } else { | ||
| 4183 | ✗ | a = floatget(a_ptr); | |
| 4184 | ✗ | b = floatget(b_ptr); | |
| 4185 | } | ||
| 4186 |
4/4✓ Branch 0 taken 125 times.
✓ Branch 1 taken 345 times.
✓ Branch 2 taken 77 times.
✓ Branch 3 taken 268 times.
|
470 | return (a < b) ? -1 : (a > b) ? 1 : 0; |
| 4187 | } | ||
| 4188 | |||
| 4189 | 3975 | size_t Field_float::make_sort_key(uchar *to, | |
| 4190 | size_t length [[maybe_unused]]) const { | ||
| 4191 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3975 times.
|
3975 | assert(length == sizeof(float)); |
| 4192 | float nr; | ||
| 4193 |
2/2✓ Branch 0 taken 3969 times.
✓ Branch 1 taken 6 times.
|
3975 | if (table->s->db_low_byte_first) |
| 4194 | 3969 | nr = float4get(ptr); | |
| 4195 | else | ||
| 4196 | 6 | nr = floatget(ptr); | |
| 4197 | |||
| 4198 | /* | ||
| 4199 | -0.0 and +0.0 compare identically, so make sure they use exactly the same | ||
| 4200 | bit pattern. | ||
| 4201 | */ | ||
| 4202 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 3959 times.
|
3975 | if (nr == 0.0f) nr = 0.0f; |
| 4203 | |||
| 4204 | /* | ||
| 4205 | Positive floats sort exactly as ints; negative floats need | ||
| 4206 | bit flipping. The bit flipping sets the upper bit to 0 | ||
| 4207 | unconditionally, so put 1 in there for positive numbers | ||
| 4208 | (so they sort later for our unsigned comparison). | ||
| 4209 | NOTE: This does not sort infinities or NaN correctly. | ||
| 4210 | */ | ||
| 4211 | int32 nr_int; | ||
| 4212 | 3975 | memcpy(&nr_int, &nr, sizeof(nr)); | |
| 4213 | 3975 | nr_int = (nr_int ^ (nr_int >> 31)) | ((~nr_int) & 0x80000000); | |
| 4214 |
1/2✓ Branch 0 taken 3975 times.
✗ Branch 1 not taken.
|
3975 | store32be(to, nr_int); |
| 4215 | |||
| 4216 | 3975 | return sizeof(float); | |
| 4217 | } | ||
| 4218 | |||
| 4219 | 25600 | bool Field_float::send_to_protocol(Protocol *protocol) const { | |
| 4220 |
3/6✓ Branch 0 taken 25600 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25600 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 25600 times.
|
25600 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4221 |
2/2✓ Branch 0 taken 733 times.
✓ Branch 1 taken 24867 times.
|
25600 | if (is_null()) return protocol->store_null(); |
| 4222 | 24867 | return protocol->store_float(static_cast<float>(Field_float::val_real()), dec, | |
| 4223 |
2/2✓ Branch 0 taken 9066 times.
✓ Branch 1 taken 15801 times.
|
49734 | zerofill ? field_length : 0); |
| 4224 | } | ||
| 4225 | |||
| 4226 | /** | ||
| 4227 | Save the field metadata for float fields. | ||
| 4228 | |||
| 4229 | Saves the pack length in the first byte. | ||
| 4230 | |||
| 4231 | @param metadata_ptr First byte of field metadata | ||
| 4232 | |||
| 4233 | @returns number of bytes written to metadata_ptr | ||
| 4234 | */ | ||
| 4235 | 18375 | int Field_float::do_save_field_metadata(uchar *metadata_ptr) const { | |
| 4236 | 18375 | *metadata_ptr = pack_length(); | |
| 4237 | 18375 | return 1; | |
| 4238 | } | ||
| 4239 | |||
| 4240 | 63301 | void Field_float::sql_type(String &res) const { | |
| 4241 |
2/2✓ Branch 0 taken 16796 times.
✓ Branch 1 taken 46505 times.
|
63301 | if (dec == DECIMAL_NOT_SPECIFIED) { |
| 4242 | 16796 | res.set_ascii(STRING_WITH_LEN("float")); | |
| 4243 | } else { | ||
| 4244 | 46505 | const CHARSET_INFO *cs = res.charset(); | |
| 4245 | 46505 | res.length(cs->cset->snprintf(cs, res.ptr(), res.alloced_length(), | |
| 4246 | 46505 | "float(%d,%d)", (int)field_length, dec)); | |
| 4247 | } | ||
| 4248 | 63301 | append_zerofill_and_unsigned(this, &res); | |
| 4249 | 63301 | } | |
| 4250 | |||
| 4251 | /**************************************************************************** | ||
| 4252 | double precision floating point numbers | ||
| 4253 | ****************************************************************************/ | ||
| 4254 | |||
| 4255 | 145183 | type_conversion_status Field_double::store(const char *from, size_t len, | |
| 4256 | const CHARSET_INFO *cs) { | ||
| 4257 |
1/2✓ Branch 0 taken 145183 times.
✗ Branch 1 not taken.
|
145183 | THD *thd = current_thd; |
| 4258 | |||
| 4259 | int conv_error; | ||
| 4260 | 145183 | type_conversion_status error = TYPE_OK; | |
| 4261 | const char *end; | ||
| 4262 |
1/2✓ Branch 0 taken 145183 times.
✗ Branch 1 not taken.
|
145183 | double nr = my_strntod(cs, from, len, &end, &conv_error); |
| 4263 |
6/6✓ Branch 0 taken 145164 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 5401 times.
✓ Branch 3 taken 139763 times.
✓ Branch 4 taken 139795 times.
✓ Branch 5 taken 5388 times.
|
150584 | if (conv_error != 0 || end == from || |
| 4264 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 5386 times.
|
5401 | (((uint)(end - from) != len && |
| 4265 |
3/4✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 2 times.
|
15 | !check_if_only_end_space(cs, end, from + len) && |
| 4266 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | thd->check_for_truncated_fields))) { |
| 4267 |
1/2✓ Branch 0 taken 139795 times.
✗ Branch 1 not taken.
|
139795 | set_warning(Sql_condition::SL_WARNING, |
| 4268 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 139776 times.
|
139795 | (conv_error ? ER_WARN_DATA_OUT_OF_RANGE : WARN_DATA_TRUNCATED), |
| 4269 | 1); | ||
| 4270 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 139776 times.
|
139795 | error = conv_error ? TYPE_WARN_OUT_OF_RANGE : TYPE_WARN_TRUNCATED; |
| 4271 | } | ||
| 4272 |
1/2✓ Branch 0 taken 145183 times.
✗ Branch 1 not taken.
|
145183 | Field_double::store(nr); |
| 4273 | 145183 | return error; | |
| 4274 | } | ||
| 4275 | |||
| 4276 | 3030450 | type_conversion_status Field_double::store(double nr) { | |
| 4277 |
4/6✓ Branch 0 taken 3030450 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3029328 times.
✓ Branch 3 taken 1122 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3029328 times.
|
3030450 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 4278 | const type_conversion_status error = | ||
| 4279 |
2/2✓ Branch 0 taken 130 times.
✓ Branch 1 taken 3030320 times.
|
3030450 | truncate(&nr, DBL_MAX) ? TYPE_WARN_OUT_OF_RANGE : TYPE_OK; |
| 4280 | |||
| 4281 |
2/2✓ Branch 0 taken 3030401 times.
✓ Branch 1 taken 49 times.
|
3030450 | if (table->s->db_low_byte_first) |
| 4282 | 3030401 | float8store(ptr, nr); | |
| 4283 | else | ||
| 4284 | 50 | doublestore(ptr, nr); | |
| 4285 | 3030451 | return error; | |
| 4286 | } | ||
| 4287 | |||
| 4288 | 8662 | type_conversion_status Field_double::store(longlong nr, bool unsigned_val) { | |
| 4289 |
2/2✓ Branch 0 taken 964 times.
✓ Branch 1 taken 7698 times.
|
8662 | return Field_double::store(unsigned_val ? ulonglong2double((ulonglong)nr) |
| 4290 | 8662 | : (double)nr); | |
| 4291 | } | ||
| 4292 | |||
| 4293 | /** | ||
| 4294 | If a field has fixed length, truncate the double argument pointed to by 'nr' | ||
| 4295 | appropriately. | ||
| 4296 | Also ensure that the argument is within [min_value; max_value] where | ||
| 4297 | min_value == 0 if unsigned_flag is set, else -max_value. | ||
| 4298 | |||
| 4299 | @param[in,out] nr the real number (FLOAT or DOUBLE) to be truncated | ||
| 4300 | @param[in] max_value the maximum (absolute) value of the real type | ||
| 4301 | |||
| 4302 | @returns truncation result | ||
| 4303 | */ | ||
| 4304 | |||
| 4305 | 3994446 | Field_real::Truncate_result Field_real::truncate(double *nr, double max_value) { | |
| 4306 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3994446 times.
|
3994446 | if (std::isnan(*nr)) { |
| 4307 | ✗ | *nr = 0; | |
| 4308 | ✗ | set_null(); | |
| 4309 | ✗ | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 4310 | ✗ | return TR_POSITIVE_OVERFLOW; | |
| 4311 |
6/6✓ Branch 0 taken 7177 times.
✓ Branch 1 taken 3987269 times.
✓ Branch 2 taken 124 times.
✓ Branch 3 taken 7053 times.
✓ Branch 4 taken 124 times.
✓ Branch 5 taken 3994322 times.
|
3994446 | } else if (is_unsigned() && *nr < 0) { |
| 4312 | 124 | *nr = 0; | |
| 4313 | 124 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 4314 | 124 | return TR_NEGATIVE_OVERFLOW; | |
| 4315 | } | ||
| 4316 | |||
| 4317 |
2/2✓ Branch 0 taken 1034840 times.
✓ Branch 1 taken 2959482 times.
|
3994322 | if (!not_fixed) { |
| 4318 | 1034840 | double orig_max_value = max_value; | |
| 4319 | 1034840 | uint order = field_length - dec; | |
| 4320 | 1034840 | uint step = array_elements(log_10) - 1; | |
| 4321 | 1034840 | max_value = 1.0; | |
| 4322 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1034840 times.
|
1034840 | for (; order > step; order -= step) max_value *= log_10[step]; |
| 4323 | 1034840 | max_value *= log_10[order]; | |
| 4324 | 1034840 | max_value -= 1.0 / log_10[dec]; | |
| 4325 | 1034840 | max_value = std::min(max_value, orig_max_value); | |
| 4326 | |||
| 4327 | /* Check for infinity so we don't get NaN in calculations */ | ||
| 4328 |
1/2✓ Branch 0 taken 1034840 times.
✗ Branch 1 not taken.
|
1034840 | if (!std::isinf(*nr)) { |
| 4329 | 1034840 | double tmp = rint((*nr - floor(*nr)) * log_10[dec]) / log_10[dec]; | |
| 4330 | 1034840 | *nr = floor(*nr) + tmp; | |
| 4331 | } | ||
| 4332 | } | ||
| 4333 | |||
| 4334 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 3994214 times.
|
3994322 | if (*nr < -max_value) { |
| 4335 | 108 | *nr = -max_value; | |
| 4336 | 108 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 4337 | 108 | return TR_NEGATIVE_OVERFLOW; | |
| 4338 |
2/2✓ Branch 0 taken 271 times.
✓ Branch 1 taken 3993943 times.
|
3994214 | } else if (*nr > max_value) { |
| 4339 | 271 | *nr = max_value; | |
| 4340 | 271 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 4341 | 271 | return TR_POSITIVE_OVERFLOW; | |
| 4342 | } | ||
| 4343 | |||
| 4344 | 3993943 | return TR_OK; | |
| 4345 | } | ||
| 4346 | |||
| 4347 | 770375 | type_conversion_status Field_real::store_decimal(const my_decimal *dm) { | |
| 4348 | double dbl; | ||
| 4349 |
1/2✓ Branch 0 taken 770375 times.
✗ Branch 1 not taken.
|
770375 | my_decimal2double(E_DEC_FATAL_ERROR, dm, &dbl); |
| 4350 |
1/2✓ Branch 0 taken 770375 times.
✗ Branch 1 not taken.
|
1540750 | return store(dbl); |
| 4351 | } | ||
| 4352 | |||
| 4353 | 9193594 | double Field_double::val_real() const { | |
| 4354 |
4/6✓ Branch 0 taken 9193594 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9193545 times.
✓ Branch 3 taken 49 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9193545 times.
|
9193594 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4355 |
2/2✓ Branch 0 taken 9193544 times.
✓ Branch 1 taken 50 times.
|
9193594 | if (table->s->db_low_byte_first) |
| 4356 | 9193544 | return float8get(ptr); | |
| 4357 | else | ||
| 4358 | 50 | return doubleget(ptr); | |
| 4359 | } | ||
| 4360 | |||
| 4361 | 2108 | longlong Field_double::val_int() const { | |
| 4362 |
3/6✓ Branch 0 taken 2108 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2108 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2108 times.
|
2108 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4363 | double j; | ||
| 4364 | longlong res; | ||
| 4365 |
1/2✓ Branch 0 taken 2108 times.
✗ Branch 1 not taken.
|
2108 | if (table->s->db_low_byte_first) |
| 4366 | 2108 | j = float8get(ptr); | |
| 4367 | else | ||
| 4368 | ✗ | j = doubleget(ptr); | |
| 4369 | /* Check whether we fit into longlong range */ | ||
| 4370 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 2083 times.
|
2108 | if (j <= LLONG_MIN) { |
| 4371 | 25 | res = (longlong)LLONG_MIN; | |
| 4372 | 25 | goto warn; | |
| 4373 | } | ||
| 4374 |
2/2✓ Branch 0 taken 158 times.
✓ Branch 1 taken 1925 times.
|
2083 | if (j >= LLONG_MAX_DOUBLE) { |
| 4375 | 158 | res = LLONG_MAX; | |
| 4376 | 158 | goto warn; | |
| 4377 | } | ||
| 4378 | 1925 | return (longlong)rint(j); | |
| 4379 | |||
| 4380 | 183 | warn : { | |
| 4381 | char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE]; | ||
| 4382 | 183 | String tmp(buf, sizeof(buf), &my_charset_latin1), *str; | |
| 4383 |
1/2✓ Branch 0 taken 183 times.
✗ Branch 1 not taken.
|
183 | str = val_str(&tmp, nullptr); |
| 4384 |
1/2✓ Branch 0 taken 183 times.
✗ Branch 1 not taken.
|
183 | ErrConvString err(str); |
| 4385 | 183 | push_warning_printf( | |
| 4386 |
2/4✓ Branch 0 taken 183 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 183 times.
✗ Branch 3 not taken.
|
183 | current_thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE, |
| 4387 |
2/4✓ Branch 0 taken 183 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 183 times.
✗ Branch 3 not taken.
|
183 | ER_THD(current_thd, ER_TRUNCATED_WRONG_VALUE), "INTEGER", err.ptr()); |
| 4388 | 183 | } | |
| 4389 | 183 | return res; | |
| 4390 | } | ||
| 4391 | |||
| 4392 | 104 | my_decimal *Field_real::val_decimal(my_decimal *decimal_value) const { | |
| 4393 |
3/6✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 104 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 104 times.
|
104 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4394 | 104 | double2my_decimal(E_DEC_FATAL_ERROR, val_real(), decimal_value); | |
| 4395 | 104 | return decimal_value; | |
| 4396 | } | ||
| 4397 | |||
| 4398 | 62 | bool Field_real::get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const { | |
| 4399 | 62 | return my_double_to_datetime_with_warn(val_real(), ltime, fuzzydate); | |
| 4400 | } | ||
| 4401 | |||
| 4402 | 46 | bool Field_real::get_time(MYSQL_TIME *ltime) const { | |
| 4403 | 46 | return my_double_to_time_with_warn(val_real(), ltime); | |
| 4404 | } | ||
| 4405 | |||
| 4406 | 16164 | String *Field_double::val_str(String *val_buffer, String *) const { | |
| 4407 |
4/6✓ Branch 0 taken 16164 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15048 times.
✓ Branch 3 taken 1116 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 15048 times.
|
16164 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4408 |
3/4✓ Branch 0 taken 926 times.
✓ Branch 1 taken 15238 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 926 times.
|
16164 | assert(!zerofill || field_length <= MAX_FIELD_CHARLENGTH); |
| 4409 | double nr; | ||
| 4410 |
2/4✓ Branch 0 taken 16164 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16164 times.
✗ Branch 3 not taken.
|
16164 | if (table && table->s->db_low_byte_first) |
| 4411 | 16164 | nr = float8get(ptr); | |
| 4412 | else | ||
| 4413 | ✗ | nr = doubleget(ptr); | |
| 4414 | 16164 | uint to_length = DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE; | |
| 4415 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16164 times.
|
16164 | if (val_buffer->alloc(to_length)) { |
| 4416 | ✗ | my_error(ER_OUT_OF_RESOURCES, MYF(0)); | |
| 4417 | ✗ | return val_buffer; | |
| 4418 | } | ||
| 4419 | |||
| 4420 | 16164 | char *to = val_buffer->ptr(); | |
| 4421 | size_t len; | ||
| 4422 | |||
| 4423 |
2/2✓ Branch 0 taken 12885 times.
✓ Branch 1 taken 3279 times.
|
16164 | if (dec >= DECIMAL_NOT_SPECIFIED) |
| 4424 | // +2 to avoid rounding errors when converting back to double. | ||
| 4425 | len = | ||
| 4426 | 12885 | my_gcvt(nr, MY_GCVT_ARG_DOUBLE, MAX_DOUBLE_STR_LENGTH + 2, to, nullptr); | |
| 4427 | else | ||
| 4428 | 3279 | len = my_fcvt(nr, dec, to, nullptr); | |
| 4429 | |||
| 4430 | 16164 | val_buffer->length((uint)len); | |
| 4431 |
2/2✓ Branch 0 taken 926 times.
✓ Branch 1 taken 15238 times.
|
16164 | if (zerofill) prepend_zeros(val_buffer); |
| 4432 | 16164 | val_buffer->set_charset(&my_charset_numeric); | |
| 4433 | 16164 | return val_buffer; | |
| 4434 | } | ||
| 4435 | |||
| 4436 | 798206 | bool Field_double::send_to_protocol(Protocol *protocol) const { | |
| 4437 |
2/2✓ Branch 0 taken 4496 times.
✓ Branch 1 taken 793710 times.
|
798206 | if (is_null()) return protocol->store_null(); |
| 4438 | 793710 | return protocol->store_double(Field_double::val_real(), dec, | |
| 4439 |
2/2✓ Branch 0 taken 5065 times.
✓ Branch 1 taken 788645 times.
|
1587420 | zerofill ? field_length : 0); |
| 4440 | } | ||
| 4441 | |||
| 4442 | 1201 | int Field_double::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 4443 | double a, b; | ||
| 4444 |
1/2✓ Branch 0 taken 1201 times.
✗ Branch 1 not taken.
|
1201 | if (table->s->db_low_byte_first) { |
| 4445 | 1201 | a = float8get(a_ptr); | |
| 4446 | 1201 | b = float8get(b_ptr); | |
| 4447 | } else { | ||
| 4448 | ✗ | a = doubleget(a_ptr); | |
| 4449 | ✗ | b = doubleget(b_ptr); | |
| 4450 | } | ||
| 4451 |
4/4✓ Branch 0 taken 210 times.
✓ Branch 1 taken 991 times.
✓ Branch 2 taken 113 times.
✓ Branch 3 taken 878 times.
|
1201 | return (a < b) ? -1 : (a > b) ? 1 : 0; |
| 4452 | } | ||
| 4453 | |||
| 4454 | /* The following should work for IEEE */ | ||
| 4455 | |||
| 4456 | 6122 | size_t Field_double::make_sort_key(uchar *to, size_t length) const { | |
| 4457 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6122 times.
|
6122 | assert(length == sizeof(double)); |
| 4458 | double nr; | ||
| 4459 |
2/2✓ Branch 0 taken 6116 times.
✓ Branch 1 taken 6 times.
|
6122 | if (table->s->db_low_byte_first) |
| 4460 | 6116 | nr = float8get(ptr); | |
| 4461 | else | ||
| 4462 | 6 | nr = doubleget(ptr); | |
| 4463 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6122 times.
|
6122 | if (length < 8) { |
| 4464 | uchar buff[8]; | ||
| 4465 | ✗ | change_double_for_sort(nr, buff); | |
| 4466 | ✗ | memcpy(to, buff, length); | |
| 4467 | } else | ||
| 4468 | 6122 | change_double_for_sort(nr, to); | |
| 4469 | 6122 | return sizeof(double); | |
| 4470 | } | ||
| 4471 | |||
| 4472 | /** | ||
| 4473 | Save the field metadata for double fields. | ||
| 4474 | |||
| 4475 | Saves the pack length in the first byte of the field metadata array | ||
| 4476 | at index of *metadata_ptr. | ||
| 4477 | |||
| 4478 | @param metadata_ptr First byte of field metadata | ||
| 4479 | |||
| 4480 | @returns number of bytes written to metadata_ptr | ||
| 4481 | */ | ||
| 4482 | 21629 | int Field_double::do_save_field_metadata(uchar *metadata_ptr) const { | |
| 4483 | 21629 | *metadata_ptr = pack_length(); | |
| 4484 | 21629 | return 1; | |
| 4485 | } | ||
| 4486 | |||
| 4487 | 18049 | void Field_double::sql_type(String &res) const { | |
| 4488 | 18049 | const CHARSET_INFO *cs = res.charset(); | |
| 4489 |
2/2✓ Branch 0 taken 10997 times.
✓ Branch 1 taken 7052 times.
|
18049 | if (dec == DECIMAL_NOT_SPECIFIED) { |
| 4490 | 10997 | res.set_ascii(STRING_WITH_LEN("double")); | |
| 4491 | } else { | ||
| 4492 | 7052 | res.length(cs->cset->snprintf(cs, res.ptr(), res.alloced_length(), | |
| 4493 | 7052 | "double(%d,%d)", (int)field_length, dec)); | |
| 4494 | } | ||
| 4495 | 18049 | append_zerofill_and_unsigned(this, &res); | |
| 4496 | 18049 | } | |
| 4497 | |||
| 4498 | /**************************************************************************** | ||
| 4499 | ** Common code for all temporal data types: DATE, DATETIME, TIMESTAMP, TIME | ||
| 4500 | *****************************************************************************/ | ||
| 4501 | |||
| 4502 | 10104216 | my_time_flags_t Field_temporal::date_flags() const { | |
| 4503 | 10104216 | return date_flags(current_thd); | |
| 4504 | } | ||
| 4505 | |||
| 4506 | 16497 | uint Field_temporal::is_equal(const Create_field *new_field) const { | |
| 4507 |
2/2✓ Branch 0 taken 16438 times.
✓ Branch 1 taken 59 times.
|
32935 | return new_field->sql_type == real_type() && |
| 4508 |
2/2✓ Branch 0 taken 16401 times.
✓ Branch 1 taken 37 times.
|
32935 | new_field->decimals == decimals(); |
| 4509 | } | ||
| 4510 | |||
| 4511 | 24 | my_decimal *Field_temporal::val_decimal(my_decimal *decimal_value) const { | |
| 4512 |
3/6✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
|
24 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4513 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | assert(decimals() == 0); |
| 4514 | 24 | int2my_decimal(E_DEC_FATAL_ERROR, val_int(), false, decimal_value); | |
| 4515 | 24 | return decimal_value; | |
| 4516 | } | ||
| 4517 | |||
| 4518 | 4338 | bool Field_temporal::set_warnings(const ErrConvString &str, int warnings) { | |
| 4519 | 4338 | bool truncate_incremented = false; | |
| 4520 | 4338 | enum_mysql_timestamp_type ts_type = field_type_to_timestamp_type(type()); | |
| 4521 | |||
| 4522 |
2/2✓ Branch 0 taken 1311 times.
✓ Branch 1 taken 3027 times.
|
4338 | if (warnings & MYSQL_TIME_WARN_TRUNCATED) { |
| 4523 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 1260 times.
|
1311 | if (set_datetime_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, |
| 4524 | 1311 | str, ts_type, !truncate_incremented)) | |
| 4525 | 51 | return true; | |
| 4526 | 1260 | truncate_incremented = true; | |
| 4527 | } | ||
| 4528 |
2/2✓ Branch 0 taken 1180 times.
✓ Branch 1 taken 3107 times.
|
4287 | if (warnings & (MYSQL_TIME_WARN_OUT_OF_RANGE | MYSQL_TIME_WARN_ZERO_DATE | |
| 4529 | MYSQL_TIME_WARN_ZERO_IN_DATE)) { | ||
| 4530 |
2/2✓ Branch 0 taken 226 times.
✓ Branch 1 taken 954 times.
|
1180 | if (set_datetime_warning(Sql_condition::SL_WARNING, |
| 4531 | ER_WARN_DATA_OUT_OF_RANGE, str, ts_type, | ||
| 4532 | 1180 | !truncate_incremented)) | |
| 4533 | 226 | return true; | |
| 4534 | 954 | truncate_incremented = true; | |
| 4535 | } | ||
| 4536 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4048 times.
|
4061 | if (warnings & MYSQL_TIME_WARN_INVALID_TIMESTAMP) { |
| 4537 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (set_datetime_warning(Sql_condition::SL_WARNING, |
| 4538 | ER_WARN_INVALID_TIMESTAMP, str, ts_type, | ||
| 4539 | 13 | !truncate_incremented)) | |
| 4540 | ✗ | return true; | |
| 4541 | 13 | truncate_incremented = true; | |
| 4542 | } | ||
| 4543 |
2/2✓ Branch 0 taken 1835 times.
✓ Branch 1 taken 2226 times.
|
4061 | if ((warnings & MYSQL_TIME_NOTE_TRUNCATED) && |
| 4544 |
1/2✓ Branch 0 taken 1835 times.
✗ Branch 1 not taken.
|
1835 | !(warnings & MYSQL_TIME_WARN_TRUNCATED)) { |
| 4545 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1835 times.
|
1835 | if (set_datetime_warning(Sql_condition::SL_NOTE, WARN_DATA_TRUNCATED, str, |
| 4546 | 1835 | ts_type, !truncate_incremented)) | |
| 4547 | ✗ | return true; | |
| 4548 | } | ||
| 4549 | 4061 | return false; | |
| 4550 | } | ||
| 4551 | |||
| 4552 | 1893360 | type_conversion_status Field_temporal::store(longlong nr, bool unsigned_val) { | |
| 4553 |
5/6✓ Branch 0 taken 1893354 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 1893301 times.
✓ Branch 3 taken 53 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1893301 times.
|
1893360 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 4554 | 1893360 | int warnings = 0; | |
| 4555 | MYSQL_TIME ltime; | ||
| 4556 | type_conversion_status error = | ||
| 4557 |
1/2✓ Branch 0 taken 1893364 times.
✗ Branch 1 not taken.
|
1893360 | convert_number_to_TIME(nr, unsigned_val, 0, <ime, &warnings); |
| 4558 |
3/4✓ Branch 0 taken 405 times.
✓ Branch 1 taken 1892959 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 405 times.
|
1893364 | if (error == TYPE_OK || error == TYPE_NOTE_TRUNCATED) |
| 4559 |
1/2✓ Branch 0 taken 1892963 times.
✗ Branch 1 not taken.
|
1892959 | error = store_internal(<ime, &warnings); |
| 4560 | else { | ||
| 4561 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 405 times.
|
405 | assert(warnings != 0); // Must be set by convert_number_to_TIME |
| 4562 | |||
| 4563 |
4/4✓ Branch 0 taken 31 times.
✓ Branch 1 taken 374 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 395 times.
|
436 | if (warnings & (MYSQL_TIME_WARN_ZERO_DATE | MYSQL_TIME_WARN_ZERO_IN_DATE) && |
| 4564 |
3/4✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 21 times.
|
31 | !current_thd->is_strict_mode()) |
| 4565 | 10 | error = TYPE_NOTE_TIME_TRUNCATED; | |
| 4566 | } | ||
| 4567 |
8/10✓ Branch 0 taken 434 times.
✓ Branch 1 taken 1892934 times.
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 434 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 20 times.
✓ Branch 7 taken 414 times.
✓ Branch 8 taken 20 times.
✓ Branch 9 taken 1893348 times.
|
1893368 | if (warnings && set_warnings(ErrConvString(nr, unsigned_val), warnings)) |
| 4568 | 20 | return TYPE_ERR_BAD_VALUE; | |
| 4569 | |||
| 4570 | 1893348 | return error; | |
| 4571 | } | ||
| 4572 | |||
| 4573 | 1197 | type_conversion_status Field_temporal::store_lldiv_t(const lldiv_t *lld, | |
| 4574 | int *warnings) { | ||
| 4575 |
4/6✓ Branch 0 taken 1191 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 1191 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1191 times.
|
1197 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 4576 | type_conversion_status error; | ||
| 4577 | MYSQL_TIME ltime; | ||
| 4578 |
1/2✓ Branch 0 taken 1197 times.
✗ Branch 1 not taken.
|
1197 | error = convert_number_to_TIME(lld->quot, false, static_cast<int>(lld->rem), |
| 4579 | <ime, warnings); | ||
| 4580 |
4/4✓ Branch 0 taken 234 times.
✓ Branch 1 taken 963 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 222 times.
|
1197 | if (error == TYPE_OK || error == TYPE_NOTE_TRUNCATED) |
| 4581 |
1/2✓ Branch 0 taken 975 times.
✗ Branch 1 not taken.
|
975 | error = store_internal_adjust_frac(<ime, warnings); |
| 4582 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 222 times.
|
222 | else if (!*warnings) { |
| 4583 | ✗ | assert(warnings != nullptr); // Must be set by convert_number_to_TIME | |
| 4584 | ✗ | if (((*warnings & MYSQL_TIME_WARN_ZERO_DATE) != 0 || | |
| 4585 | ✗ | (*warnings & MYSQL_TIME_WARN_ZERO_IN_DATE) != 0) && | |
| 4586 | ✗ | !current_thd->is_strict_mode()) | |
| 4587 | ✗ | error = TYPE_NOTE_TIME_TRUNCATED; | |
| 4588 | } | ||
| 4589 | |||
| 4590 | 1197 | return error; | |
| 4591 | } | ||
| 4592 | |||
| 4593 | 669 | type_conversion_status Field_temporal::store_decimal( | |
| 4594 | const my_decimal *decimal) { | ||
| 4595 |
4/6✓ Branch 0 taken 666 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 666 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 666 times.
|
669 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 4596 | lldiv_t lld; | ||
| 4597 | 669 | int warnings = 0; | |
| 4598 | /* Pass 0 in the first argument, not to produce warnings automatically */ | ||
| 4599 |
1/2✓ Branch 0 taken 669 times.
✗ Branch 1 not taken.
|
669 | my_decimal2lldiv_t(0, decimal, &lld); |
| 4600 |
1/2✓ Branch 0 taken 669 times.
✗ Branch 1 not taken.
|
669 | const type_conversion_status error = store_lldiv_t(&lld, &warnings); |
| 4601 |
8/10✓ Branch 0 taken 158 times.
✓ Branch 1 taken 511 times.
✓ Branch 2 taken 158 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 158 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 153 times.
✓ Branch 8 taken 5 times.
✓ Branch 9 taken 664 times.
|
669 | if (warnings && set_warnings(ErrConvString(decimal), warnings)) |
| 4602 | 5 | return TYPE_ERR_BAD_VALUE; | |
| 4603 | |||
| 4604 | 664 | return error; | |
| 4605 | } | ||
| 4606 | |||
| 4607 | 528 | type_conversion_status Field_temporal::store(double nr) { | |
| 4608 |
4/6✓ Branch 0 taken 525 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 525 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 525 times.
|
528 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 4609 | 528 | int warnings = 0; | |
| 4610 | lldiv_t lld; | ||
| 4611 |
1/2✓ Branch 0 taken 528 times.
✗ Branch 1 not taken.
|
528 | double2lldiv_t(nr, &lld); |
| 4612 |
1/2✓ Branch 0 taken 528 times.
✗ Branch 1 not taken.
|
528 | const type_conversion_status error = store_lldiv_t(&lld, &warnings); |
| 4613 |
8/10✓ Branch 0 taken 131 times.
✓ Branch 1 taken 397 times.
✓ Branch 2 taken 131 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 131 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 127 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 524 times.
|
528 | if (warnings && set_warnings(ErrConvString(nr), warnings)) |
| 4614 | 4 | return TYPE_ERR_BAD_VALUE; | |
| 4615 | |||
| 4616 | 524 | return error; | |
| 4617 | } | ||
| 4618 | |||
| 4619 | /** | ||
| 4620 | Store string into a date/time/datetime field. | ||
| 4621 | |||
| 4622 | @param str Date/time string | ||
| 4623 | @param len Length of the string | ||
| 4624 | @param cs Character set of the string | ||
| 4625 | |||
| 4626 | @retval TYPE_OK Storage of value went fine without warnings or errors | ||
| 4627 | @retval !TYPE_OK Warning/error as indicated by type_conversion_status enum | ||
| 4628 | value | ||
| 4629 | */ | ||
| 4630 | 109927 | type_conversion_status Field_temporal::store(const char *str, size_t len, | |
| 4631 | const CHARSET_INFO *cs) { | ||
| 4632 |
5/6✓ Branch 0 taken 109924 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 85310 times.
✓ Branch 3 taken 24614 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 85310 times.
|
109927 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 4633 | 109927 | type_conversion_status error = TYPE_OK; | |
| 4634 | MYSQL_TIME ltime; | ||
| 4635 | 109927 | MYSQL_TIME_STATUS status; | |
| 4636 |
3/4✓ Branch 0 taken 109927 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1228 times.
✓ Branch 3 taken 108699 times.
|
109927 | if (convert_str_to_TIME(str, len, cs, <ime, &status)) { |
| 4637 | /* | ||
| 4638 | When convert_str_to_TIME() returns error, ltime has been set to | ||
| 4639 | 0 so there's nothing to store in the field. | ||
| 4640 | */ | ||
| 4641 |
1/2✓ Branch 0 taken 1228 times.
✗ Branch 1 not taken.
|
1228 | reset(); |
| 4642 | 2456 | if (status.warnings & | |
| 4643 |
4/4✓ Branch 0 taken 415 times.
✓ Branch 1 taken 813 times.
✓ Branch 2 taken 110 times.
✓ Branch 3 taken 1118 times.
|
1643 | (MYSQL_TIME_WARN_ZERO_DATE | MYSQL_TIME_WARN_ZERO_IN_DATE) && |
| 4644 |
3/4✓ Branch 0 taken 415 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 110 times.
✓ Branch 3 taken 305 times.
|
415 | !current_thd->is_strict_mode()) |
| 4645 | 110 | error = TYPE_NOTE_TIME_TRUNCATED; | |
| 4646 | else | ||
| 4647 | 1118 | error = TYPE_ERR_BAD_VALUE; | |
| 4648 | } else { | ||
| 4649 |
2/4✓ Branch 0 taken 108699 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 108699 times.
✗ Branch 3 not taken.
|
108699 | check_deprecated_datetime_format(current_thd, cs, status); |
| 4650 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 108619 times.
|
108699 | if (ltime.time_type == MYSQL_TIMESTAMP_DATETIME_TZ) { |
| 4651 | /* | ||
| 4652 | Convert the timestamp with timezone to without timezone. This is a | ||
| 4653 | lossy conversion for edge cases like for the repeat hour of the | ||
| 4654 | DST switch, but useful for the boundary conditions check. | ||
| 4655 | */ | ||
| 4656 | 80 | MYSQL_TIME tmp_ltime = ltime; | |
| 4657 |
4/6✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 76 times.
|
80 | if (convert_time_zone_displacement(current_thd->time_zone(), &tmp_ltime)) |
| 4658 | 4 | return TYPE_ERR_BAD_VALUE; | |
| 4659 | // check for boundary conditions by converting to a timeval | ||
| 4660 | my_timeval tm_not_used; | ||
| 4661 |
2/4✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 76 times.
|
76 | if (datetime_with_no_zero_in_date_to_timeval( |
| 4662 |
1/2✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
|
76 | &tmp_ltime, *current_thd->time_zone(), &tm_not_used, |
| 4663 | &status.warnings)) { | ||
| 4664 | ✗ | if (status.warnings && | |
| 4665 | ✗ | set_warnings(ErrConvString(str, len, cs), status.warnings)) | |
| 4666 | ✗ | return TYPE_WARN_OUT_OF_RANGE; | |
| 4667 | ✗ | return TYPE_WARN_OUT_OF_RANGE; | |
| 4668 | } | ||
| 4669 | } | ||
| 4670 | 108695 | error = time_warning_to_type_conversion_status(status.warnings); | |
| 4671 | const type_conversion_status tmp_error = | ||
| 4672 |
1/2✓ Branch 0 taken 108695 times.
✗ Branch 1 not taken.
|
108695 | store_internal_adjust_frac(<ime, &status.warnings); |
| 4673 | |||
| 4674 | // Return the most serious error of the two, see type_conversion_status | ||
| 4675 |
2/2✓ Branch 0 taken 1429 times.
✓ Branch 1 taken 107266 times.
|
108695 | if (tmp_error > error) error = tmp_error; |
| 4676 | } | ||
| 4677 |
2/2✓ Branch 0 taken 2812 times.
✓ Branch 1 taken 107111 times.
|
112735 | if (status.warnings && |
| 4678 |
6/8✓ Branch 0 taken 2812 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2812 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 158 times.
✓ Branch 5 taken 2654 times.
✓ Branch 6 taken 158 times.
✓ Branch 7 taken 109765 times.
|
112735 | set_warnings(ErrConvString(str, len, cs), status.warnings)) |
| 4679 | 158 | return TYPE_ERR_BAD_VALUE; | |
| 4680 | |||
| 4681 | 109765 | return error; | |
| 4682 | } | ||
| 4683 | |||
| 4684 | 1893393 | longlong Field_temporal::convert_number_to_datetime(longlong nr, bool, | |
| 4685 | MYSQL_TIME *ltime, | ||
| 4686 | int *warnings) { | ||
| 4687 | /* | ||
| 4688 | Note, number_to_datetime can return a result different from nr: | ||
| 4689 | e.g. 111111 -> 20111111000000 | ||
| 4690 | */ | ||
| 4691 | 1893393 | longlong tmp = number_to_datetime(nr, ltime, date_flags(), warnings); | |
| 4692 |
2/2✓ Branch 0 taken 475 times.
✓ Branch 1 taken 1892922 times.
|
1893397 | if (tmp == -1LL) reset(); |
| 4693 | 1893398 | return tmp; | |
| 4694 | } | ||
| 4695 | |||
| 4696 | /**************************************************************************** | ||
| 4697 | ** Common code for temporal data types with date: DATE, DATETIME, TIMESTAMP | ||
| 4698 | *****************************************************************************/ | ||
| 4699 | |||
| 4700 | 431605 | bool Field_temporal_with_date::get_internal_check_zero( | |
| 4701 | MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const { | ||
| 4702 |
2/2✓ Branch 0 taken 294 times.
✓ Branch 1 taken 431312 times.
|
431605 | if (get_date_internal(ltime)) /* '0000-00-00' */ |
| 4703 | { | ||
| 4704 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 294 times.
|
294 | assert(type() == MYSQL_TYPE_TIMESTAMP); |
| 4705 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 268 times.
|
294 | if (fuzzydate & TIME_NO_ZERO_DATE) return true; |
| 4706 | 268 | set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME); | |
| 4707 | } | ||
| 4708 | 431580 | return false; | |
| 4709 | } | ||
| 4710 | |||
| 4711 | 21656 | longlong Field_temporal_with_date::val_date_temporal() const { | |
| 4712 |
3/6✓ Branch 0 taken 21656 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21656 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 21656 times.
|
21656 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4713 | MYSQL_TIME ltime; | ||
| 4714 |
3/4✓ Branch 0 taken 21656 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1582 times.
✓ Branch 3 taken 20074 times.
|
21656 | return get_date_internal(<ime) ? 0 |
| 4715 |
1/2✓ Branch 0 taken 20074 times.
✗ Branch 1 not taken.
|
21656 | : TIME_to_longlong_datetime_packed(ltime); |
| 4716 | } | ||
| 4717 | |||
| 4718 | ✗ | longlong Field_temporal_with_date::val_time_temporal() const { | |
| 4719 | ✗ | ASSERT_COLUMN_MARKED_FOR_READ; | |
| 4720 | MYSQL_TIME ltime; | ||
| 4721 | ✗ | return get_date_internal(<ime) ? 0 : TIME_to_longlong_time_packed(ltime); | |
| 4722 | } | ||
| 4723 | |||
| 4724 | 43850 | longlong Field_temporal_with_date::val_date_temporal_at_utc() const { | |
| 4725 |
3/6✓ Branch 0 taken 43850 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43850 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 43850 times.
|
43850 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4726 | MYSQL_TIME ltime; | ||
| 4727 |
1/2✓ Branch 0 taken 43850 times.
✗ Branch 1 not taken.
|
43850 | return get_date_internal_at_utc(<ime) |
| 4728 |
2/2✓ Branch 0 taken 927 times.
✓ Branch 1 taken 42923 times.
|
43850 | ? 0 |
| 4729 |
1/2✓ Branch 0 taken 42923 times.
✗ Branch 1 not taken.
|
43850 | : TIME_to_longlong_datetime_packed(ltime); |
| 4730 | } | ||
| 4731 | |||
| 4732 | ✗ | longlong Field_temporal_with_date::val_time_temporal_at_utc() const { | |
| 4733 | /* | ||
| 4734 | There are currently no tests covering this method, | ||
| 4735 | as DATETIME seems to always superseed over TIME in comparison. | ||
| 4736 | */ | ||
| 4737 | ✗ | ASSERT_COLUMN_MARKED_FOR_READ; | |
| 4738 | MYSQL_TIME ltime; | ||
| 4739 | ✗ | return get_date_internal_at_utc(<ime) ? 0 | |
| 4740 | ✗ | : TIME_to_longlong_time_packed(ltime); | |
| 4741 | } | ||
| 4742 | |||
| 4743 | /** | ||
| 4744 | Convert a number in format YYMMDDhhmmss to string. | ||
| 4745 | Straight coded to avoid problem with slow longlong arithmetic and sprintf. | ||
| 4746 | |||
| 4747 | @param[out] pos pointer to convert to. | ||
| 4748 | @param tmp number with datetime value. | ||
| 4749 | */ | ||
| 4750 | 138 | static inline int my_datetime_number_to_str(char *pos, longlong tmp) { | |
| 4751 | 138 | long part1 = (long)(tmp / 1000000LL); | |
| 4752 | 138 | long part2 = (long)(tmp - (ulonglong)part1 * 1000000LL); | |
| 4753 | int part3; | ||
| 4754 | 138 | pos += MAX_DATETIME_WIDTH; /* Start from the end */ | |
| 4755 | 138 | *pos-- = 0; | |
| 4756 | 138 | *pos-- = (char)('0' + (char)(part2 % 10)); /* Seconds */ | |
| 4757 | 138 | part2 /= 10; | |
| 4758 | 138 | *pos-- = (char)('0' + (char)(part2 % 10)); | |
| 4759 | 138 | part3 = (int)(part2 / 10); | |
| 4760 | 138 | *pos-- = ':'; | |
| 4761 | 138 | *pos-- = (char)('0' + (char)(part3 % 10)); /* Minutes */ | |
| 4762 | 138 | part3 /= 10; | |
| 4763 | 138 | *pos-- = (char)('0' + (char)(part3 % 10)); | |
| 4764 | 138 | part3 /= 10; | |
| 4765 | 138 | *pos-- = ':'; | |
| 4766 | 138 | *pos-- = (char)('0' + (char)(part3 % 10)); /* Hours */ | |
| 4767 | 138 | part3 /= 10; | |
| 4768 | 138 | *pos-- = (char)('0' + (char)part3); | |
| 4769 | 138 | *pos-- = ' '; | |
| 4770 | 138 | *pos-- = (char)('0' + (char)(part1 % 10)); /* Day */ | |
| 4771 | 138 | part1 /= 10; | |
| 4772 | 138 | *pos-- = (char)('0' + (char)(part1 % 10)); | |
| 4773 | 138 | part1 /= 10; | |
| 4774 | 138 | *pos-- = '-'; | |
| 4775 | 138 | *pos-- = (char)('0' + (char)(part1 % 10)); /* Month */ | |
| 4776 | 138 | part1 /= 10; | |
| 4777 | 138 | *pos-- = (char)('0' + (char)(part1 % 10)); | |
| 4778 | 138 | part3 = (int)(part1 / 10); | |
| 4779 | 138 | *pos-- = '-'; | |
| 4780 | 138 | *pos-- = (char)('0' + (char)(part3 % 10)); /* Year */ | |
| 4781 | 138 | part3 /= 10; | |
| 4782 | 138 | *pos-- = (char)('0' + (char)(part3 % 10)); | |
| 4783 | 138 | part3 /= 10; | |
| 4784 | 138 | *pos-- = (char)('0' + (char)(part3 % 10)); | |
| 4785 | 138 | part3 /= 10; | |
| 4786 | 138 | *pos = (char)('0' + (char)part3); | |
| 4787 | 138 | return MAX_DATETIME_WIDTH; | |
| 4788 | } | ||
| 4789 | |||
| 4790 | 176724 | String *Field_temporal_with_date::val_str(String *val_buffer, String *) const { | |
| 4791 |
4/6✓ Branch 0 taken 176724 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 152900 times.
✓ Branch 3 taken 23824 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 152900 times.
|
176724 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4792 | MYSQL_TIME ltime; | ||
| 4793 |
1/2✓ Branch 0 taken 176724 times.
✗ Branch 1 not taken.
|
176724 | val_buffer->alloc(field_length + 1); |
| 4794 | 176724 | val_buffer->set_charset(&my_charset_numeric); | |
| 4795 |
3/4✓ Branch 0 taken 176724 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1076 times.
✓ Branch 3 taken 175648 times.
|
176724 | if (get_date_internal(<ime)) { |
| 4796 |
1/2✓ Branch 0 taken 1076 times.
✗ Branch 1 not taken.
|
1076 | val_buffer->set_ascii(my_zero_datetime6, field_length); |
| 4797 | 1076 | return val_buffer; | |
| 4798 | } | ||
| 4799 |
1/2✓ Branch 0 taken 175648 times.
✗ Branch 1 not taken.
|
175648 | make_datetime((Date_time_format *)nullptr, <ime, val_buffer, dec); |
| 4800 | 175648 | return val_buffer; | |
| 4801 | } | ||
| 4802 | |||
| 4803 | 1893427 | type_conversion_status Field_temporal_with_date::convert_number_to_TIME( | |
| 4804 | longlong nr, bool unsigned_val, int nanoseconds, MYSQL_TIME *ltime, | ||
| 4805 | int *warnings) { | ||
| 4806 |
4/4✓ Branch 0 taken 1893399 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1893395 times.
|
1893427 | if (nr < 0 || nanoseconds < 0) { |
| 4807 | 34 | reset(); | |
| 4808 | 34 | *warnings |= MYSQL_TIME_WARN_OUT_OF_RANGE; | |
| 4809 | 34 | return TYPE_WARN_OUT_OF_RANGE; | |
| 4810 | } | ||
| 4811 | |||
| 4812 |
2/2✓ Branch 0 taken 475 times.
✓ Branch 1 taken 1892923 times.
|
1893395 | if (convert_number_to_datetime(nr, unsigned_val, ltime, warnings) == -1LL) |
| 4813 | 475 | return TYPE_ERR_BAD_VALUE; | |
| 4814 | |||
| 4815 |
4/4✓ Branch 0 taken 456 times.
✓ Branch 1 taken 1892467 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 444 times.
|
1892923 | if (ltime->time_type == MYSQL_TIMESTAMP_DATE && nanoseconds) { |
| 4816 | 12 | *warnings |= MYSQL_TIME_WARN_TRUNCATED; | |
| 4817 | 12 | return TYPE_NOTE_TRUNCATED; | |
| 4818 | } | ||
| 4819 | |||
| 4820 | 1892911 | ltime->second_part = 0; | |
| 4821 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1892906 times.
|
1892912 | if (propagate_datetime_overflow(current_thd, warnings, |
| 4822 | 1892907 | datetime_add_nanoseconds_adjust_frac( | |
| 4823 | ltime, nanoseconds, warnings, | ||
| 4824 | 1892911 | (date_flags() & TIME_FRAC_TRUNCATE)))) { | |
| 4825 | 1 | reset(); | |
| 4826 | 1 | return TYPE_WARN_OUT_OF_RANGE; | |
| 4827 | } | ||
| 4828 | 1892906 | return TYPE_OK; | |
| 4829 | } | ||
| 4830 | |||
| 4831 | 3047058 | type_conversion_status Field_temporal_with_date::store_time(MYSQL_TIME *ltime, | |
| 4832 | uint8) { | ||
| 4833 |
4/6✓ Branch 0 taken 3047058 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3047020 times.
✓ Branch 3 taken 38 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3047023 times.
|
3047058 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 4834 | type_conversion_status error; | ||
| 4835 | 3047061 | int warnings = 0; | |
| 4836 | |||
| 4837 |
3/3✓ Branch 0 taken 3046856 times.
✓ Branch 1 taken 195 times.
✓ Branch 2 taken 10 times.
|
3047061 | switch (ltime->time_type) // TS-TODO: split into separate methods? |
| 4838 | { | ||
| 4839 | 3046856 | case MYSQL_TIMESTAMP_DATETIME: | |
| 4840 | case MYSQL_TIMESTAMP_DATETIME_TZ: | ||
| 4841 | case MYSQL_TIMESTAMP_DATE: | ||
| 4842 |
4/6✓ Branch 0 taken 3046853 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3046848 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 327 times.
✓ Branch 5 taken 3046521 times.
|
3046856 | if (check_date(*ltime, non_zero_date(*ltime), date_flags(), &warnings)) { |
| 4843 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 327 times.
|
327 | assert(warnings & |
| 4844 | (MYSQL_TIME_WARN_OUT_OF_RANGE | MYSQL_TIME_WARN_ZERO_DATE | | ||
| 4845 | MYSQL_TIME_WARN_ZERO_IN_DATE)); | ||
| 4846 | |||
| 4847 | 327 | error = time_warning_to_type_conversion_status(warnings); | |
| 4848 |
1/2✓ Branch 0 taken 327 times.
✗ Branch 1 not taken.
|
327 | reset(); |
| 4849 | } else { | ||
| 4850 |
1/2✓ Branch 0 taken 3046525 times.
✗ Branch 1 not taken.
|
3046521 | error = store_internal_adjust_frac(ltime, &warnings); |
| 4851 | } | ||
| 4852 | 3046852 | break; | |
| 4853 | 195 | case MYSQL_TIMESTAMP_TIME: { | |
| 4854 | /* Convert TIME to DATETIME */ | ||
| 4855 |
1/2✓ Branch 0 taken 195 times.
✗ Branch 1 not taken.
|
195 | THD *thd = current_thd; |
| 4856 | MYSQL_TIME ltime2; | ||
| 4857 |
1/2✓ Branch 0 taken 195 times.
✗ Branch 1 not taken.
|
195 | time_to_datetime(thd, ltime, <ime2); |
| 4858 |
1/2✓ Branch 0 taken 195 times.
✗ Branch 1 not taken.
|
195 | error = store_internal_adjust_frac(<ime2, &warnings); |
| 4859 | 195 | break; | |
| 4860 | } | ||
| 4861 | 10 | case MYSQL_TIMESTAMP_NONE: | |
| 4862 | case MYSQL_TIMESTAMP_ERROR: | ||
| 4863 | default: | ||
| 4864 | 10 | warnings |= MYSQL_TIME_WARN_TRUNCATED; | |
| 4865 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | reset(); |
| 4866 | 10 | error = TYPE_WARN_TRUNCATED; | |
| 4867 | } | ||
| 4868 | |||
| 4869 |
9/12✓ Branch 0 taken 803 times.
✓ Branch 1 taken 3046254 times.
✓ Branch 2 taken 803 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 803 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 803 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 90 times.
✓ Branch 9 taken 713 times.
✓ Branch 10 taken 90 times.
✓ Branch 11 taken 3046967 times.
|
3047057 | if (warnings && set_warnings(ErrConvString(ltime, decimals()), warnings)) |
| 4870 | 90 | return TYPE_ERR_BAD_VALUE; | |
| 4871 | |||
| 4872 | 3046967 | return error; | |
| 4873 | } | ||
| 4874 | |||
| 4875 | 96693 | bool Field_temporal_with_date::convert_str_to_TIME(const char *str, size_t len, | |
| 4876 | const CHARSET_INFO *cs, | ||
| 4877 | MYSQL_TIME *ltime, | ||
| 4878 | MYSQL_TIME_STATUS *status) { | ||
| 4879 | 290079 | return propagate_datetime_overflow( | |
| 4880 | 96693 | current_thd, &status->warnings, | |
| 4881 | 193386 | str_to_datetime(cs, str, len, ltime, date_flags(), status)); | |
| 4882 | } | ||
| 4883 | |||
| 4884 | 8603617 | bool Field_temporal_with_date::send_to_protocol(Protocol *protocol) const { | |
| 4885 |
4/6✓ Branch 0 taken 8603575 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8076349 times.
✓ Branch 3 taken 527226 times.
✓ Branch 4 taken 8076349 times.
✗ Branch 5 not taken.
|
8603617 | if (is_null()) return protocol->store_null(); |
| 4886 | MYSQL_TIME ltime; | ||
| 4887 |
3/4✓ Branch 0 taken 527309 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2358 times.
✓ Branch 3 taken 524951 times.
|
527226 | if (get_date_internal(<ime)) { |
| 4888 | // Only MYSQL_TYPE_TIMESTAMP can return an error in get_date_internal() | ||
| 4889 |
2/4✓ Branch 0 taken 2358 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2358 times.
|
2358 | assert(type() == MYSQL_TYPE_TIMESTAMP); |
| 4890 |
1/2✓ Branch 0 taken 2358 times.
✗ Branch 1 not taken.
|
2358 | set_zero_time(<ime, MYSQL_TIMESTAMP_DATETIME); |
| 4891 | } | ||
| 4892 |
1/2✓ Branch 0 taken 527282 times.
✗ Branch 1 not taken.
|
527309 | return protocol->store_datetime(ltime, dec); |
| 4893 | } | ||
| 4894 | |||
| 4895 | 3142854 | type_conversion_status Field_temporal_with_date::store_internal_adjust_frac( | |
| 4896 | MYSQL_TIME *ltime, int *warnings) { | ||
| 4897 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3142853 times.
|
3142854 | if (propagate_datetime_overflow( |
| 4898 | 3142859 | current_thd, warnings, | |
| 4899 | 3142859 | my_datetime_adjust_frac(ltime, dec, warnings, | |
| 4900 | 3142854 | (date_flags() & TIME_FRAC_TRUNCATE)))) { | |
| 4901 | 1 | reset(); | |
| 4902 | 1 | return time_warning_to_type_conversion_status(*warnings); | |
| 4903 | } else | ||
| 4904 | 3142853 | return store_internal(ltime, warnings); | |
| 4905 | } | ||
| 4906 | |||
| 4907 | /** | ||
| 4908 | Validate date value stored in the field. | ||
| 4909 | |||
| 4910 | Now we check whether date value is zero or has zero in date or not and sets | ||
| 4911 | warning/error message appropriately(depending on the sql_mode). | ||
| 4912 | */ | ||
| 4913 | 491 | type_conversion_status Field_temporal_with_date::validate_stored_val(THD *) { | |
| 4914 | MYSQL_TIME ltime; | ||
| 4915 | 491 | type_conversion_status error = TYPE_OK; | |
| 4916 | 491 | int warnings = 0; | |
| 4917 | |||
| 4918 |
3/4✓ Branch 0 taken 491 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 287 times.
✓ Branch 3 taken 204 times.
|
491 | if (is_real_null()) return error; |
| 4919 | |||
| 4920 | 204 | memset(<ime, 0, sizeof(MYSQL_TIME)); | |
| 4921 |
1/2✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
|
204 | get_date_internal(<ime); |
| 4922 |
3/6✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 204 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 204 times.
|
204 | if (check_date(ltime, non_zero_date(ltime), date_flags(), &warnings)) |
| 4923 | ✗ | error = time_warning_to_type_conversion_status(warnings); | |
| 4924 | |||
| 4925 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 204 times.
|
204 | if (warnings) { |
| 4926 | ✗ | ltime.time_type = field_type_to_timestamp_type(type()); | |
| 4927 | ✗ | if (set_warnings(ErrConvString(<ime, dec), warnings)) | |
| 4928 | ✗ | return TYPE_ERR_BAD_VALUE; | |
| 4929 | } | ||
| 4930 | |||
| 4931 | 204 | return error; | |
| 4932 | } | ||
| 4933 | |||
| 4934 | /**************************************************************************** | ||
| 4935 | ** Common code for data types with date and time: DATETIME, TIMESTAMP | ||
| 4936 | *****************************************************************************/ | ||
| 4937 | |||
| 4938 | 4710502 | void Field_temporal_with_date_and_time::store_timestamp(const my_timeval *tm) { | |
| 4939 |
3/6✓ Branch 0 taken 4710502 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4710502 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4710502 times.
|
4710502 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 4940 |
3/4✓ Branch 0 taken 4710502 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4709068 times.
✓ Branch 3 taken 1434 times.
|
4710502 | if (!my_time_fraction_remainder(tm->m_tv_usec, decimals())) { |
| 4941 |
1/2✓ Branch 0 taken 4709068 times.
✗ Branch 1 not taken.
|
4709068 | store_timestamp_internal(tm); |
| 4942 | 4709068 | return; | |
| 4943 | } | ||
| 4944 | 1434 | my_timeval tm2 = *tm; | |
| 4945 |
2/4✓ Branch 0 taken 1434 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1434 times.
✗ Branch 3 not taken.
|
1434 | my_timeval_round(&tm2, decimals()); |
| 4946 |
1/2✓ Branch 0 taken 1434 times.
✗ Branch 1 not taken.
|
1434 | store_timestamp_internal(&tm2); |
| 4947 | } | ||
| 4948 | |||
| 4949 | 2011403 | bool Field_temporal_with_date_and_time::convert_TIME_to_timestamp( | |
| 4950 | const MYSQL_TIME *ltime, const Time_zone &tz, my_timeval *tm, | ||
| 4951 | int *warnings) { | ||
| 4952 | /* | ||
| 4953 | No need to do check_date(TIME_NO_ZERO_IN_DATE), | ||
| 4954 | because it has been done earlier in | ||
| 4955 | store_time(), number_to_datetime() or str_to_datetime(). | ||
| 4956 | */ | ||
| 4957 |
2/2✓ Branch 0 taken 74 times.
✓ Branch 1 taken 2011333 times.
|
2011403 | if (datetime_with_no_zero_in_date_to_timeval(ltime, tz, tm, warnings)) { |
| 4958 | 74 | tm->m_tv_sec = tm->m_tv_usec = 0; | |
| 4959 | 74 | return true; | |
| 4960 | } | ||
| 4961 | // Check if the time since epoch fits in TIMESTAMP. | ||
| 4962 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2011287 times.
|
2011333 | if (tm->m_tv_sec > TYPE_TIMESTAMP_MAX_VALUE) { |
| 4963 | 46 | tm->m_tv_sec = tm->m_tv_usec = 0; | |
| 4964 | 46 | *warnings |= MYSQL_TIME_WARN_OUT_OF_RANGE; | |
| 4965 | } | ||
| 4966 | |||
| 4967 | 2011333 | return false; | |
| 4968 | } | ||
| 4969 | |||
| 4970 | 1709341 | void Field_temporal_with_date_and_time::init_timestamp_flags() { | |
| 4971 |
4/4✓ Branch 0 taken 410983 times.
✓ Branch 1 taken 1298358 times.
✓ Branch 2 taken 410774 times.
✓ Branch 3 taken 209 times.
|
1709341 | if (auto_flags != NONE && (!(auto_flags & GENERATED_FROM_EXPRESSION))) { |
| 4972 | /* | ||
| 4973 | This TIMESTAMP column is hereby quietly assumed to have an insert or | ||
| 4974 | update default function. | ||
| 4975 | */ | ||
| 4976 | 410774 | set_flag(TIMESTAMP_FLAG); | |
| 4977 |
2/2✓ Branch 0 taken 353359 times.
✓ Branch 1 taken 57415 times.
|
410774 | if (auto_flags & ON_UPDATE_NOW) set_flag(ON_UPDATE_NOW_FLAG); |
| 4978 | } | ||
| 4979 | 1709341 | } | |
| 4980 | |||
| 4981 | /**************************************************************************** | ||
| 4982 | ** Common code for DATETIME(N) and TIMESTAMP(N) | ||
| 4983 | *****************************************************************************/ | ||
| 4984 | |||
| 4985 | 387 | double Field_temporal_with_date_and_timef::val_real() const { | |
| 4986 |
3/6✓ Branch 0 taken 387 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 387 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 387 times.
|
387 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4987 | MYSQL_TIME ltime; | ||
| 4988 |
4/6✓ Branch 0 taken 387 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 375 times.
✓ Branch 4 taken 375 times.
✗ Branch 5 not taken.
|
387 | return get_date_internal(<ime) ? 0 : TIME_to_double_datetime(ltime); |
| 4989 | } | ||
| 4990 | |||
| 4991 | 7283894 | longlong Field_temporal_with_date_and_timef::val_int() const { | |
| 4992 |
3/6✓ Branch 0 taken 7283894 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7283894 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7283894 times.
|
7283894 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 4993 | MYSQL_TIME ltime; | ||
| 4994 |
1/2✓ Branch 0 taken 7283894 times.
✗ Branch 1 not taken.
|
7283894 | return get_date_internal(<ime) |
| 4995 |
2/2✓ Branch 0 taken 4866 times.
✓ Branch 1 taken 7279028 times.
|
7283894 | ? 0 |
| 4996 |
2/4✓ Branch 0 taken 7279028 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7279028 times.
✗ Branch 3 not taken.
|
7279028 | : propagate_datetime_overflow(current_thd, [&](int *w) { |
| 4997 | 7279028 | return TIME_to_ulonglong_datetime_round(ltime, w); | |
| 4998 | 7283894 | }); | |
| 4999 | } | ||
| 5000 | |||
| 5001 | 187 | my_decimal *Field_temporal_with_date_and_timef::val_decimal( | |
| 5002 | my_decimal *dec_arg) const { | ||
| 5003 |
3/6✓ Branch 0 taken 187 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 187 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 187 times.
|
187 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5004 | MYSQL_TIME ltime; | ||
| 5005 |
2/4✓ Branch 0 taken 187 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 187 times.
|
187 | if (get_date_internal(<ime)) { |
| 5006 | // Only MYSQL_TYPE_TIMESTAMP can return an error in get_date_internal() | ||
| 5007 | ✗ | assert(type() == MYSQL_TYPE_TIMESTAMP); | |
| 5008 | ✗ | set_zero_time(<ime, MYSQL_TIMESTAMP_DATETIME); | |
| 5009 | } | ||
| 5010 |
1/2✓ Branch 0 taken 187 times.
✗ Branch 1 not taken.
|
374 | return date2my_decimal(<ime, dec_arg); |
| 5011 | } | ||
| 5012 | |||
| 5013 | /** | ||
| 5014 | TIMESTAMP type columns hold date and time values in the range 1970-01-01 | ||
| 5015 | 00:00:01 UTC to 2038-01-01 00:00:00 UTC, stored as number of seconds since | ||
| 5016 | the start of the Unix Epoch (1970-01-01 00:00:01 UTC.) | ||
| 5017 | |||
| 5018 | TIMESTAMP columns can be automatically set on row updates to and/or have | ||
| 5019 | CURRENT_TIMESTAMP as default value for inserts. | ||
| 5020 | We use flags Field::auto_flags member to control this behavior. | ||
| 5021 | */ | ||
| 5022 | 55 | Field_timestamp::Field_timestamp(uchar *ptr_arg, uint32, uchar *null_ptr_arg, | |
| 5023 | uchar null_bit_arg, uchar auto_flags_arg, | ||
| 5024 | 55 | const char *field_name_arg) | |
| 5025 | : Field_temporal_with_date_and_time(ptr_arg, null_ptr_arg, null_bit_arg, | ||
| 5026 | 55 | auto_flags_arg, field_name_arg, 0) { | |
| 5027 |
1/2✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
|
55 | init_timestamp_flags(); |
| 5028 | /* For 4.0 MYD and 4.0 InnoDB compatibility */ | ||
| 5029 | 55 | set_flag(ZEROFILL_FLAG); | |
| 5030 | 55 | set_flag(UNSIGNED_FLAG); | |
| 5031 | 55 | } | |
| 5032 | |||
| 5033 | 3 | Field_timestamp::Field_timestamp(bool is_nullable_arg, | |
| 5034 | 3 | const char *field_name_arg) | |
| 5035 | : Field_temporal_with_date_and_time( | ||
| 5036 | nullptr, is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE, | ||
| 5037 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | field_name_arg, 0) { |
| 5038 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | init_timestamp_flags(); |
| 5039 | /* For 4.0 MYD and 4.0 InnoDB compatibility */ | ||
| 5040 | 3 | set_flag(ZEROFILL_FLAG); | |
| 5041 | 3 | set_flag(UNSIGNED_FLAG); | |
| 5042 | 3 | } | |
| 5043 | |||
| 5044 | 6 | my_time_flags_t Field_timestamp::date_flags(const THD *thd) const { | |
| 5045 | /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */ | ||
| 5046 | 6 | my_time_flags_t date_flags = TIME_NO_ZERO_IN_DATE; | |
| 5047 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (thd->variables.sql_mode & MODE_NO_ZERO_DATE) |
| 5048 | 6 | date_flags |= TIME_NO_ZERO_DATE; | |
| 5049 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (thd->variables.sql_mode & MODE_TIME_TRUNCATE_FRACTIONAL) |
| 5050 | ✗ | date_flags |= TIME_FRAC_TRUNCATE; | |
| 5051 | |||
| 5052 | 6 | return date_flags; | |
| 5053 | } | ||
| 5054 | |||
| 5055 | 3 | type_conversion_status Field_timestamp::store_internal(const MYSQL_TIME *ltime, | |
| 5056 | int *warnings) { | ||
| 5057 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | THD *thd = current_thd; |
| 5058 | my_timeval tm; | ||
| 5059 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | convert_TIME_to_timestamp(ltime, *thd->time_zone(), &tm, warnings); |
| 5060 | const type_conversion_status error = | ||
| 5061 | 3 | time_warning_to_type_conversion_status(*warnings); | |
| 5062 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | store_timestamp_internal(&tm); |
| 5063 | 3 | return error; | |
| 5064 | } | ||
| 5065 | |||
| 5066 | 7 | bool Field_timestamp::get_date_internal(MYSQL_TIME *ltime) const { | |
| 5067 | 7 | THD *thd = current_thd; | |
| 5068 | 7 | return get_date_internal_at(thd->time_zone(), ltime); | |
| 5069 | } | ||
| 5070 | |||
| 5071 | ✗ | bool Field_timestamp::get_date_internal_at_utc(MYSQL_TIME *ltime) const { | |
| 5072 | ✗ | return get_date_internal_at(my_tz_UTC, ltime); | |
| 5073 | } | ||
| 5074 | |||
| 5075 | 7 | bool Field_timestamp::get_date_internal_at(const Time_zone *tz, | |
| 5076 | MYSQL_TIME *ltime) const { | ||
| 5077 |
3/6✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
|
7 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5078 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | my_time_t temp = (table != nullptr && table->s->db_low_byte_first) |
| 5079 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
14 | ? uint4korr(ptr) |
| 5080 | ✗ | : ulongget(ptr); | |
| 5081 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
|
7 | if (temp == 0) return true; |
| 5082 | |||
| 5083 | 4 | tz->gmt_sec_to_TIME(ltime, temp); | |
| 5084 | 4 | return false; | |
| 5085 | } | ||
| 5086 | |||
| 5087 | /** | ||
| 5088 | Get TIMESTAMP field value as seconds since begging of Unix Epoch | ||
| 5089 | */ | ||
| 5090 | 48 | bool Field_timestamp::get_timestamp(my_timeval *tm, int *) const { | |
| 5091 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (is_null()) return true; |
| 5092 | 48 | tm->m_tv_usec = 0; | |
| 5093 |
2/4✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | if (table && table->s->db_low_byte_first) { |
| 5094 | 48 | tm->m_tv_sec = sint4korr(ptr); | |
| 5095 | 48 | return false; | |
| 5096 | } | ||
| 5097 | ✗ | tm->m_tv_sec = longget(ptr); | |
| 5098 | ✗ | return false; | |
| 5099 | } | ||
| 5100 | |||
| 5101 | 18 | void Field_timestamp::store_timestamp_internal(const my_timeval *tm) { | |
| 5102 |
2/4✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
18 | if (table && table->s->db_low_byte_first) |
| 5103 | 18 | int4store(ptr, tm->m_tv_sec); | |
| 5104 | else | ||
| 5105 | ✗ | longstore(ptr, (uint32)tm->m_tv_sec); | |
| 5106 | 18 | } | |
| 5107 | |||
| 5108 | ✗ | type_conversion_status Field_timestamp::store_packed(longlong nr) { | |
| 5109 | /* Make sure the stored value was previously properly rounded or truncated */ | ||
| 5110 | ✗ | assert((my_packed_time_get_frac_part(nr) % | |
| 5111 | (int)log_10_int[DATETIME_MAX_DECIMALS - decimals()]) == 0); | ||
| 5112 | MYSQL_TIME ltime; | ||
| 5113 | ✗ | TIME_from_longlong_datetime_packed(<ime, nr); | |
| 5114 | ✗ | return Field_timestamp::store_time(<ime, 0); | |
| 5115 | } | ||
| 5116 | |||
| 5117 | ✗ | longlong Field_timestamp::val_int() const { | |
| 5118 | ✗ | ASSERT_COLUMN_MARKED_FOR_READ; | |
| 5119 | MYSQL_TIME ltime; | ||
| 5120 | ✗ | return get_date_internal(<ime) ? 0 : TIME_to_ulonglong_datetime(ltime); | |
| 5121 | } | ||
| 5122 | |||
| 5123 | 2 | bool Field_timestamp::get_date(MYSQL_TIME *ltime, | |
| 5124 | my_time_flags_t fuzzydate) const { | ||
| 5125 | /* Don't do check_fuzzy_date() as month and year are never 0 for timestamp */ | ||
| 5126 | 2 | return get_internal_check_zero(ltime, fuzzydate); | |
| 5127 | } | ||
| 5128 | |||
| 5129 | ✗ | int Field_timestamp::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 5130 | int32 a, b; | ||
| 5131 | ✗ | if (table && table->s->db_low_byte_first) { | |
| 5132 | ✗ | a = sint4korr(a_ptr); | |
| 5133 | ✗ | b = sint4korr(b_ptr); | |
| 5134 | } else { | ||
| 5135 | ✗ | a = longget(a_ptr); | |
| 5136 | ✗ | b = longget(b_ptr); | |
| 5137 | } | ||
| 5138 | ✗ | return ((uint32)a < (uint32)b) ? -1 : ((uint32)a > (uint32)b) ? 1 : 0; | |
| 5139 | } | ||
| 5140 | |||
| 5141 | 6 | size_t Field_timestamp::make_sort_key(uchar *to, | |
| 5142 | size_t length [[maybe_unused]]) const { | ||
| 5143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | assert(length == 4); |
| 5144 | #ifdef WORDS_BIGENDIAN | ||
| 5145 | if (!table || !table->s->db_low_byte_first) { | ||
| 5146 | to[0] = ptr[0]; | ||
| 5147 | to[1] = ptr[1]; | ||
| 5148 | to[2] = ptr[2]; | ||
| 5149 | to[3] = ptr[3]; | ||
| 5150 | } else | ||
| 5151 | #endif | ||
| 5152 | { | ||
| 5153 | 6 | to[0] = ptr[3]; | |
| 5154 | 6 | to[1] = ptr[2]; | |
| 5155 | 6 | to[2] = ptr[1]; | |
| 5156 | 6 | to[3] = ptr[0]; | |
| 5157 | } | ||
| 5158 | 6 | return 4; | |
| 5159 | } | ||
| 5160 | |||
| 5161 | 4 | void Field_timestamp::sql_type(String &res) const { | |
| 5162 | 4 | res.set_ascii(STRING_WITH_LEN("timestamp")); | |
| 5163 | 4 | } | |
| 5164 | |||
| 5165 | ✗ | type_conversion_status Field_timestamp::validate_stored_val(THD *thd) { | |
| 5166 | /* | ||
| 5167 | While deprecating "TIMESTAMP with implicit DEFAULT value", we can | ||
| 5168 | remove this function implementation and depend directly on | ||
| 5169 | "Field_temporal_with_date::validate_stored_val" | ||
| 5170 | */ | ||
| 5171 | ✗ | if (!thd->variables.explicit_defaults_for_timestamp) return TYPE_OK; | |
| 5172 | |||
| 5173 | ✗ | return (Field_temporal_with_date::validate_stored_val(thd)); | |
| 5174 | } | ||
| 5175 | |||
| 5176 | /**************************************************************************** | ||
| 5177 | ** timestamp(N) type | ||
| 5178 | ** In string context: YYYY-MM-DD HH:MM:SS.FFFFFF | ||
| 5179 | ** In number context: YYYYMMDDHHMMSS.FFFFFF | ||
| 5180 | ** Stored as a 7 byte value | ||
| 5181 | ****************************************************************************/ | ||
| 5182 | 1709283 | Field_timestampf::Field_timestampf(uchar *ptr_arg, uchar *null_ptr_arg, | |
| 5183 | uchar null_bit_arg, uchar auto_flags_arg, | ||
| 5184 | 1709283 | const char *field_name_arg, uint8 dec_arg) | |
| 5185 | : Field_temporal_with_date_and_timef(ptr_arg, null_ptr_arg, null_bit_arg, | ||
| 5186 | auto_flags_arg, field_name_arg, | ||
| 5187 | 1709283 | dec_arg) { | |
| 5188 |
1/2✓ Branch 0 taken 1709283 times.
✗ Branch 1 not taken.
|
1709283 | init_timestamp_flags(); |
| 5189 | 1709283 | } | |
| 5190 | |||
| 5191 | 53 | Field_timestampf::Field_timestampf(bool is_nullable_arg, | |
| 5192 | 53 | const char *field_name_arg, uint8 dec_arg) | |
| 5193 | : Field_temporal_with_date_and_timef( | ||
| 5194 | nullptr, is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE, | ||
| 5195 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 51 times.
|
53 | field_name_arg, dec_arg) { |
| 5196 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
|
53 | if (auto_flags & ON_UPDATE_NOW) set_flag(ON_UPDATE_NOW_FLAG); |
| 5197 | 53 | } | |
| 5198 | |||
| 5199 | 4023781 | my_time_flags_t Field_timestampf::date_flags(const THD *thd) const { | |
| 5200 | /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */ | ||
| 5201 | 4023781 | my_time_flags_t date_flags = TIME_NO_ZERO_IN_DATE; | |
| 5202 |
2/2✓ Branch 0 taken 220580 times.
✓ Branch 1 taken 3803201 times.
|
4023781 | if (thd->variables.sql_mode & MODE_NO_ZERO_DATE) |
| 5203 | 220580 | date_flags |= TIME_NO_ZERO_DATE; | |
| 5204 |
2/2✓ Branch 0 taken 126 times.
✓ Branch 1 taken 4023655 times.
|
4023781 | if (thd->variables.sql_mode & MODE_TIME_TRUNCATE_FRACTIONAL) |
| 5205 | 126 | date_flags |= TIME_FRAC_TRUNCATE; | |
| 5206 | |||
| 5207 | 4023781 | return date_flags; | |
| 5208 | } | ||
| 5209 | |||
| 5210 | 6721629 | void Field_timestampf::store_timestamp_internal(const my_timeval *tm) { | |
| 5211 | 6721629 | my_timestamp_to_binary(tm, ptr, dec); | |
| 5212 | 6721634 | } | |
| 5213 | |||
| 5214 | 2011400 | type_conversion_status Field_timestampf::store_internal(const MYSQL_TIME *ltime, | |
| 5215 | int *warnings) { | ||
| 5216 |
1/2✓ Branch 0 taken 2011403 times.
✗ Branch 1 not taken.
|
2011400 | THD *thd = current_thd; |
| 5217 | my_timeval tm; | ||
| 5218 |
1/2✓ Branch 0 taken 2011405 times.
✗ Branch 1 not taken.
|
2011403 | convert_TIME_to_timestamp(ltime, *thd->time_zone(), &tm, warnings); |
| 5219 | const type_conversion_status error = | ||
| 5220 | 2011405 | time_warning_to_type_conversion_status(*warnings); | |
| 5221 |
1/2✓ Branch 0 taken 2011407 times.
✗ Branch 1 not taken.
|
2011400 | store_timestamp_internal(&tm); |
| 5222 | 2011407 | return error; | |
| 5223 | } | ||
| 5224 | |||
| 5225 | 21 | type_conversion_status Field_timestampf::store_packed(longlong nr) { | |
| 5226 | MYSQL_TIME ltime; | ||
| 5227 |
1/2✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
|
21 | TIME_from_longlong_datetime_packed(<ime, nr); |
| 5228 |
1/2✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
|
42 | return Field_timestampf::store_time(<ime, dec); |
| 5229 | } | ||
| 5230 | |||
| 5231 | 49205 | bool Field_timestampf::get_date(MYSQL_TIME *ltime, | |
| 5232 | my_time_flags_t fuzzydate) const { | ||
| 5233 | /* Don't do check_fuzzy_date() as month and year are never 0 for timestamp */ | ||
| 5234 | 49205 | return get_internal_check_zero(ltime, fuzzydate); | |
| 5235 | } | ||
| 5236 | |||
| 5237 | 416681 | void Field_timestampf::sql_type(String &res) const { | |
| 5238 |
2/2✓ Branch 0 taken 333009 times.
✓ Branch 1 taken 83672 times.
|
416681 | if (dec == 0) { |
| 5239 | 333009 | res.set_ascii(STRING_WITH_LEN("timestamp")); | |
| 5240 | 333009 | return; | |
| 5241 | } | ||
| 5242 | 83672 | const CHARSET_INFO *cs = res.charset(); | |
| 5243 | 83672 | res.length(cs->cset->snprintf(cs, res.ptr(), res.alloced_length(), | |
| 5244 | 83672 | "timestamp(%d)", dec)); | |
| 5245 | } | ||
| 5246 | |||
| 5247 | 7606376 | bool Field_timestampf::get_date_internal(MYSQL_TIME *ltime) const { | |
| 5248 | 7606376 | THD *thd = current_thd; | |
| 5249 | 7606376 | return get_date_internal_at(thd->time_zone(), ltime); | |
| 5250 | } | ||
| 5251 | |||
| 5252 | 14374 | bool Field_timestampf::get_date_internal_at_utc(MYSQL_TIME *ltime) const { | |
| 5253 | 14374 | return get_date_internal_at(my_tz_UTC, ltime); | |
| 5254 | } | ||
| 5255 | |||
| 5256 | 106069 | bool Field_timestampf::get_timestamp(my_timeval *tm, int *) const { | |
| 5257 | 106069 | THD *thd = current_thd; | |
| 5258 | 106069 | thd->time_zone_used = true; | |
| 5259 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 106069 times.
|
106069 | assert(!is_null()); |
| 5260 | 106069 | my_timestamp_from_binary(tm, ptr, dec); | |
| 5261 | 106069 | return false; | |
| 5262 | } | ||
| 5263 | |||
| 5264 | 7620750 | bool Field_timestampf::get_date_internal_at(const Time_zone *tz, | |
| 5265 | MYSQL_TIME *ltime) const { | ||
| 5266 | my_timeval tm; | ||
| 5267 |
1/2✓ Branch 0 taken 7620750 times.
✗ Branch 1 not taken.
|
7620750 | my_timestamp_from_binary(&tm, ptr, dec); |
| 5268 |
2/2✓ Branch 0 taken 11145 times.
✓ Branch 1 taken 7609605 times.
|
7620750 | if (tm.m_tv_sec == 0) return true; |
| 5269 |
1/2✓ Branch 0 taken 7609605 times.
✗ Branch 1 not taken.
|
7609605 | tz->gmt_sec_to_TIME(ltime, tm); |
| 5270 | 7609605 | return false; | |
| 5271 | } | ||
| 5272 | |||
| 5273 | 363 | type_conversion_status Field_timestampf::validate_stored_val(THD *thd) { | |
| 5274 | /* | ||
| 5275 | While deprecating "TIMESTAMP with implicit DEFAULT value", we can | ||
| 5276 | remove this function implementation and depend directly on | ||
| 5277 | "Field_temporal_with_date::validate_stored_val" | ||
| 5278 | */ | ||
| 5279 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 352 times.
|
363 | if (!thd->variables.explicit_defaults_for_timestamp) return TYPE_OK; |
| 5280 | |||
| 5281 | 352 | return (Field_temporal_with_date::validate_stored_val(thd)); | |
| 5282 | } | ||
| 5283 | |||
| 5284 | /**************************************************************************** | ||
| 5285 | ** TIME and TIME(N) common methods | ||
| 5286 | ****************************************************************************/ | ||
| 5287 | |||
| 5288 | 13234 | bool Field_time_common::convert_str_to_TIME(const char *str, size_t len, | |
| 5289 | const CHARSET_INFO *cs, | ||
| 5290 | MYSQL_TIME *ltime, | ||
| 5291 | MYSQL_TIME_STATUS *status) { | ||
| 5292 | 13234 | return str_to_time(cs, str, len, ltime, date_flags(), status); | |
| 5293 | } | ||
| 5294 | |||
| 5295 | 1131 | type_conversion_status Field_time_common::convert_number_to_TIME( | |
| 5296 | longlong nr, bool unsigned_val, int nanoseconds, MYSQL_TIME *ltime, | ||
| 5297 | int *warnings) { | ||
| 5298 |
4/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1126 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
|
1131 | if (unsigned_val && nr < 0) { |
| 5299 | 2 | *warnings |= MYSQL_TIME_WARN_OUT_OF_RANGE; | |
| 5300 | 2 | set_max_time(ltime, false); | |
| 5301 | 2 | store_internal(ltime, warnings); | |
| 5302 | 2 | return TYPE_WARN_OUT_OF_RANGE; | |
| 5303 | } | ||
| 5304 |
2/2✓ Branch 0 taken 115 times.
✓ Branch 1 taken 1014 times.
|
1129 | if (number_to_time(nr, ltime, warnings)) { |
| 5305 | 115 | store_internal(ltime, warnings); | |
| 5306 | 115 | return TYPE_WARN_OUT_OF_RANGE; | |
| 5307 | } | ||
| 5308 | /* | ||
| 5309 | Both number_to_time() call and negative nanoseconds value | ||
| 5310 | affect ltime->neg, hence "|=" to combine them: | ||
| 5311 | */ | ||
| 5312 |
2/2✓ Branch 0 taken 94 times.
✓ Branch 1 taken 920 times.
|
1014 | if ((ltime->neg |= (nanoseconds < 0))) nanoseconds = -nanoseconds; |
| 5313 | 1014 | ltime->second_part = 0; | |
| 5314 | |||
| 5315 | 2028 | bool error = time_add_nanoseconds_adjust_frac( | |
| 5316 | 1014 | ltime, nanoseconds, warnings, (date_flags() & TIME_FRAC_TRUNCATE)); | |
| 5317 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1014 times.
|
1014 | return error ? time_warning_to_type_conversion_status(*warnings) : TYPE_OK; |
| 5318 | } | ||
| 5319 | |||
| 5320 | 3524 | type_conversion_status Field_time_common::store_time(MYSQL_TIME *ltime, uint8) { | |
| 5321 | /* Check if seconds or minutes are out of range */ | ||
| 5322 |
2/4✓ Branch 0 taken 3524 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3524 times.
|
3524 | if (ltime->second >= 60 || ltime->minute >= 60) { |
| 5323 | ✗ | if (set_warnings(ErrConvString(ltime, decimals()), | |
| 5324 | MYSQL_TIME_WARN_OUT_OF_RANGE)) | ||
| 5325 | ✗ | return TYPE_ERR_BAD_VALUE; | |
| 5326 | ✗ | reset(); | |
| 5327 | ✗ | return TYPE_WARN_OUT_OF_RANGE; | |
| 5328 | } | ||
| 5329 | 3524 | int warnings = 0; | |
| 5330 |
1/2✓ Branch 0 taken 3524 times.
✗ Branch 1 not taken.
|
3524 | return store_internal_adjust_frac(ltime, &warnings); |
| 5331 | } | ||
| 5332 | |||
| 5333 | 17060 | type_conversion_status Field_time_common::store_internal_adjust_frac( | |
| 5334 | MYSQL_TIME *ltime, int *warnings) { | ||
| 5335 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17060 times.
|
17060 | if (my_time_adjust_frac(ltime, dec, (date_flags() & TIME_FRAC_TRUNCATE))) |
| 5336 | ✗ | return TYPE_WARN_OUT_OF_RANGE; | |
| 5337 | |||
| 5338 | 17060 | return store_internal(ltime, warnings); | |
| 5339 | } | ||
| 5340 | |||
| 5341 | 5863 | String *Field_time_common::val_str(String *val_buffer, String *) const { | |
| 5342 |
5/6✓ Branch 0 taken 5857 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 5687 times.
✓ Branch 3 taken 170 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5687 times.
|
5863 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5343 | MYSQL_TIME ltime; | ||
| 5344 |
1/2✓ Branch 0 taken 5863 times.
✗ Branch 1 not taken.
|
5863 | val_buffer->alloc(MAX_DATE_STRING_REP_LENGTH); |
| 5345 | 5863 | val_buffer->set_charset(&my_charset_numeric); | |
| 5346 |
2/4✓ Branch 0 taken 5863 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5863 times.
|
5863 | if (get_time(<ime)) { |
| 5347 | ✗ | assert(0); | |
| 5348 | set_zero_time(<ime, MYSQL_TIMESTAMP_TIME); | ||
| 5349 | } | ||
| 5350 |
1/2✓ Branch 0 taken 5863 times.
✗ Branch 1 not taken.
|
5863 | make_time((Date_time_format *)nullptr, <ime, val_buffer, dec); |
| 5351 | 5863 | return val_buffer; | |
| 5352 | } | ||
| 5353 | |||
| 5354 | /** | ||
| 5355 | For a column for TIME type, get_date() takes the time | ||
| 5356 | value of the field, adds current date to it and returns | ||
| 5357 | the result as a DATETIME value. | ||
| 5358 | */ | ||
| 5359 | |||
| 5360 | 2816 | bool Field_time_common::get_date(MYSQL_TIME *ltime, my_time_flags_t) const { | |
| 5361 |
5/6✓ Branch 0 taken 2813 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2810 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2810 times.
|
2816 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5362 | MYSQL_TIME tm; | ||
| 5363 |
2/4✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
|
2816 | if (get_time(&tm)) { |
| 5364 | ✗ | assert(0); | |
| 5365 | set_zero_time(ltime, MYSQL_TIMESTAMP_TIME); | ||
| 5366 | } | ||
| 5367 |
2/4✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2816 times.
✗ Branch 3 not taken.
|
2816 | time_to_datetime(current_thd, &tm, ltime); |
| 5368 | 2816 | return false; | |
| 5369 | } | ||
| 5370 | |||
| 5371 | 169 | longlong Field_time_common::val_date_temporal() const { | |
| 5372 |
3/6✓ Branch 0 taken 169 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 169 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 169 times.
|
169 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5373 | MYSQL_TIME time, datetime; | ||
| 5374 |
2/4✓ Branch 0 taken 169 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 169 times.
|
169 | if (get_time(&time)) { |
| 5375 | ✗ | assert(0); // Field_time*::get_time should not fail | |
| 5376 | return 0; | ||
| 5377 | } | ||
| 5378 |
2/4✓ Branch 0 taken 169 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 169 times.
✗ Branch 3 not taken.
|
169 | time_to_datetime(current_thd, &time, &datetime); |
| 5379 |
1/2✓ Branch 0 taken 169 times.
✗ Branch 1 not taken.
|
169 | return TIME_to_longlong_datetime_packed(datetime); |
| 5380 | } | ||
| 5381 | |||
| 5382 | 18163 | bool Field_time_common::send_to_protocol(Protocol *protocol) const { | |
| 5383 |
4/6✓ Branch 0 taken 18163 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 469 times.
✓ Branch 3 taken 17694 times.
✓ Branch 4 taken 469 times.
✗ Branch 5 not taken.
|
18163 | if (is_null()) return protocol->store_null(); |
| 5384 | MYSQL_TIME ltime; | ||
| 5385 |
2/4✓ Branch 0 taken 17694 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17694 times.
|
17694 | if (get_time(<ime)) { |
| 5386 | ✗ | assert(0); | |
| 5387 | set_zero_time(<ime, MYSQL_TIMESTAMP_TIME); | ||
| 5388 | } | ||
| 5389 |
1/2✓ Branch 0 taken 17694 times.
✗ Branch 1 not taken.
|
17694 | return protocol->store_time(ltime, dec); |
| 5390 | } | ||
| 5391 | |||
| 5392 | 31308 | my_time_flags_t Field_time_common::date_flags(const THD *thd) const { | |
| 5393 | 31308 | my_time_flags_t date_flags = 0; | |
| 5394 |
2/2✓ Branch 0 taken 199 times.
✓ Branch 1 taken 31109 times.
|
31308 | if (thd->variables.sql_mode & MODE_TIME_TRUNCATE_FRACTIONAL) |
| 5395 | 199 | date_flags = TIME_FRAC_TRUNCATE; | |
| 5396 | |||
| 5397 | 31308 | return date_flags; | |
| 5398 | } | ||
| 5399 | |||
| 5400 | /**************************************************************************** | ||
| 5401 | ** time type | ||
| 5402 | ** In string context: HH:MM:SS | ||
| 5403 | ** In number context: HHMMSS | ||
| 5404 | ** Stored as a 3 byte unsigned int | ||
| 5405 | ****************************************************************************/ | ||
| 5406 | |||
| 5407 | 3 | type_conversion_status Field_time::store_internal(const MYSQL_TIME *ltime, | |
| 5408 | int *) { | ||
| 5409 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | long tmp = ((ltime->month ? 0 : ltime->day * 24L) + ltime->hour) * 10000L + |
| 5410 | 3 | (ltime->minute * 100 + ltime->second); | |
| 5411 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (ltime->neg) tmp = -tmp; |
| 5412 | 3 | int3store(ptr, tmp); | |
| 5413 | 3 | return TYPE_OK; | |
| 5414 | } | ||
| 5415 | |||
| 5416 | ✗ | type_conversion_status Field_time::store_packed(longlong nr) { | |
| 5417 | MYSQL_TIME ltime; | ||
| 5418 | ✗ | TIME_from_longlong_time_packed(<ime, nr); | |
| 5419 | ✗ | return Field_time::store_time(<ime, 0); | |
| 5420 | } | ||
| 5421 | |||
| 5422 | ✗ | longlong Field_time::val_time_temporal() const { | |
| 5423 | ✗ | ASSERT_COLUMN_MARKED_FOR_READ; | |
| 5424 | MYSQL_TIME ltime; | ||
| 5425 | ✗ | return get_time(<ime) ? 0 : TIME_to_longlong_time_packed(ltime); | |
| 5426 | } | ||
| 5427 | |||
| 5428 | ✗ | longlong Field_time::val_int() const { | |
| 5429 | ✗ | ASSERT_COLUMN_MARKED_FOR_READ; | |
| 5430 | ✗ | return (longlong)sint3korr(ptr); | |
| 5431 | } | ||
| 5432 | |||
| 5433 | 131 | bool Field_time::get_time(MYSQL_TIME *ltime) const { | |
| 5434 | 131 | long tmp = (long)sint3korr(ptr); | |
| 5435 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 131 times.
|
131 | if ((ltime->neg = tmp < 0)) tmp = -tmp; |
| 5436 | 131 | ltime->year = ltime->month = ltime->day = 0; | |
| 5437 | 131 | TIME_set_hhmmss(ltime, tmp); | |
| 5438 | 131 | ltime->second_part = 0; | |
| 5439 | 131 | ltime->time_type = MYSQL_TIMESTAMP_TIME; | |
| 5440 | 131 | return false; | |
| 5441 | } | ||
| 5442 | |||
| 5443 | ✗ | int Field_time::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 5444 | int32 a, b; | ||
| 5445 | ✗ | a = sint3korr(a_ptr); | |
| 5446 | ✗ | b = sint3korr(b_ptr); | |
| 5447 | ✗ | return (a < b) ? -1 : (a > b) ? 1 : 0; | |
| 5448 | } | ||
| 5449 | |||
| 5450 | 6 | size_t Field_time::make_sort_key(uchar *to, | |
| 5451 | size_t length [[maybe_unused]]) const { | ||
| 5452 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | assert(length == 3); |
| 5453 | 6 | to[0] = (uchar)(ptr[2] ^ 128); | |
| 5454 | 6 | to[1] = ptr[1]; | |
| 5455 | 6 | to[2] = ptr[0]; | |
| 5456 | 6 | return 3; | |
| 5457 | } | ||
| 5458 | |||
| 5459 | 65 | void Field_time::sql_type(String &res) const { | |
| 5460 | 65 | res.set_ascii(STRING_WITH_LEN("time")); | |
| 5461 | 65 | } | |
| 5462 | |||
| 5463 | /**************************************************************************** | ||
| 5464 | ** time type with fsp | ||
| 5465 | ** In string context: HH:MM:SS.FFFFFF | ||
| 5466 | ** In number context: HHMMSS.FFFFFF | ||
| 5467 | ****************************************************************************/ | ||
| 5468 | |||
| 5469 | 110 | longlong Field_timef::val_int() const { | |
| 5470 |
4/6✓ Branch 0 taken 92 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 92 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 92 times.
|
110 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5471 | MYSQL_TIME ltime; | ||
| 5472 |
2/4✓ Branch 0 taken 110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 110 times.
|
110 | if (get_time(<ime)) { |
| 5473 | ✗ | assert(0); | |
| 5474 | set_zero_time(<ime, MYSQL_TIMESTAMP_TIME); | ||
| 5475 | } | ||
| 5476 |
1/2✓ Branch 0 taken 110 times.
✗ Branch 1 not taken.
|
110 | longlong tmp = (longlong)TIME_to_ulonglong_time_round(ltime); |
| 5477 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 81 times.
|
110 | return ltime.neg ? -tmp : tmp; |
| 5478 | } | ||
| 5479 | |||
| 5480 | 94 | my_decimal *Field_timef::val_decimal(my_decimal *decimal_value) const { | |
| 5481 |
4/6✓ Branch 0 taken 91 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 91 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 91 times.
|
94 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5482 | MYSQL_TIME ltime; | ||
| 5483 |
2/4✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 94 times.
|
94 | if (get_time(<ime)) { |
| 5484 | ✗ | assert(0); | |
| 5485 | set_zero_time(<ime, MYSQL_TIMESTAMP_TIME); | ||
| 5486 | } | ||
| 5487 |
1/2✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
|
188 | return time2my_decimal(<ime, decimal_value); |
| 5488 | } | ||
| 5489 | |||
| 5490 | 171 | double Field_timef::val_real() const { | |
| 5491 |
4/6✓ Branch 0 taken 135 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 135 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 135 times.
|
171 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5492 | MYSQL_TIME ltime; | ||
| 5493 |
2/4✓ Branch 0 taken 171 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 171 times.
|
171 | if (get_time(<ime)) { |
| 5494 | ✗ | assert(0); | |
| 5495 | return 0; | ||
| 5496 | } | ||
| 5497 |
1/2✓ Branch 0 taken 171 times.
✗ Branch 1 not taken.
|
171 | double tmp = TIME_to_double_time(ltime); |
| 5498 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 148 times.
|
171 | return ltime.neg ? -tmp : tmp; |
| 5499 | } | ||
| 5500 | |||
| 5501 | 41569 | void Field_timef::sql_type(String &res) const { | |
| 5502 |
2/2✓ Branch 0 taken 38390 times.
✓ Branch 1 taken 3179 times.
|
41569 | if (dec == 0) { |
| 5503 | 38390 | res.set_ascii(STRING_WITH_LEN("time")); | |
| 5504 | 38390 | return; | |
| 5505 | } | ||
| 5506 | 3179 | const CHARSET_INFO *cs = res.charset(); | |
| 5507 | 3179 | res.length( | |
| 5508 | 3179 | cs->cset->snprintf(cs, res.ptr(), res.alloced_length(), "time(%d)", dec)); | |
| 5509 | } | ||
| 5510 | |||
| 5511 | 99233 | type_conversion_status Field_timef::reset() { return store_packed(0); } | |
| 5512 | |||
| 5513 | 117147 | type_conversion_status Field_timef::store_packed(longlong nr) { | |
| 5514 | 117147 | my_time_packed_to_binary(nr, ptr, dec); | |
| 5515 | 117147 | return TYPE_OK; | |
| 5516 | } | ||
| 5517 | |||
| 5518 | 49147 | longlong Field_timef::val_time_temporal() const { | |
| 5519 |
5/6✓ Branch 0 taken 49063 times.
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 48883 times.
✓ Branch 3 taken 180 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 48883 times.
|
49147 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5520 | 49147 | return my_time_packed_from_binary(ptr, dec); | |
| 5521 | } | ||
| 5522 | |||
| 5523 | 17856 | type_conversion_status Field_timef::store_internal(const MYSQL_TIME *ltime, | |
| 5524 | int *warnings) { | ||
| 5525 | /* | ||
| 5526 | If time zone displacement information is present in "ltime" | ||
| 5527 | - adjust the value to UTC based on the time zone | ||
| 5528 | - convert to the local time zone | ||
| 5529 | */ | ||
| 5530 | MYSQL_TIME temp_time; | ||
| 5531 | const MYSQL_TIME *time; | ||
| 5532 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17855 times.
|
17856 | if (ltime->time_type == MYSQL_TIMESTAMP_DATETIME_TZ) { |
| 5533 | 1 | temp_time = *ltime; | |
| 5534 | 1 | time = &temp_time; | |
| 5535 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | if (convert_time_zone_displacement(current_thd->time_zone(), &temp_time)) |
| 5536 | ✗ | return TYPE_ERR_BAD_VALUE; | |
| 5537 | } else { | ||
| 5538 | 17855 | time = ltime; | |
| 5539 | } | ||
| 5540 |
2/4✓ Branch 0 taken 17856 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17856 times.
✗ Branch 3 not taken.
|
17856 | type_conversion_status rc = store_packed(TIME_to_longlong_time_packed(*time)); |
| 5541 |
5/6✓ Branch 0 taken 17856 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1234 times.
✓ Branch 3 taken 16622 times.
✓ Branch 4 taken 1234 times.
✓ Branch 5 taken 16622 times.
|
17856 | if (rc == TYPE_OK && non_zero_date(*ltime)) { |
| 5542 | /* | ||
| 5543 | The DATE part got lost; we warn, like in Field_newdate::store_internal, | ||
| 5544 | and trigger some code in get_mm_leaf() | ||
| 5545 | (see err==TYPE_NOTE_TIME_TRUNCATED there). | ||
| 5546 | */ | ||
| 5547 | 1234 | *warnings |= MYSQL_TIME_NOTE_TRUNCATED; | |
| 5548 | 1234 | rc = TYPE_NOTE_TIME_TRUNCATED; | |
| 5549 | } | ||
| 5550 | 17856 | return rc; | |
| 5551 | } | ||
| 5552 | |||
| 5553 | 30150 | bool Field_timef::get_time(MYSQL_TIME *ltime) const { | |
| 5554 | 30150 | longlong tmp = val_time_temporal(); | |
| 5555 | 30150 | TIME_from_longlong_time_packed(ltime, tmp); | |
| 5556 | 30150 | return false; | |
| 5557 | } | ||
| 5558 | |||
| 5559 | /**************************************************************************** | ||
| 5560 | ** year type | ||
| 5561 | ** Save in a byte the year 0, 1901->2155 | ||
| 5562 | ****************************************************************************/ | ||
| 5563 | |||
| 5564 | 5890 | type_conversion_status Field_year::store(const char *from, size_t len, | |
| 5565 | const CHARSET_INFO *cs) { | ||
| 5566 |
4/6✓ Branch 0 taken 5890 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5787 times.
✓ Branch 3 taken 103 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5787 times.
|
5890 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 5567 | const char *end; | ||
| 5568 | int conv_error; | ||
| 5569 | 5890 | type_conversion_status ret = TYPE_OK; | |
| 5570 |
1/2✓ Branch 0 taken 5890 times.
✗ Branch 1 not taken.
|
5890 | longlong nr = cs->cset->strntoull10rnd(cs, from, len, 0, &end, &conv_error); |
| 5571 | |||
| 5572 |
8/8✓ Branch 0 taken 5840 times.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 4072 times.
✓ Branch 3 taken 1768 times.
✓ Branch 4 taken 3964 times.
✓ Branch 5 taken 108 times.
✓ Branch 6 taken 5680 times.
✓ Branch 7 taken 52 times.
|
5890 | if (nr < 0 || (nr >= 100 && nr < MIN_YEAR) || nr > MAX_YEAR || |
| 5573 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5680 times.
|
5680 | conv_error == MY_ERRNO_ERANGE) { |
| 5574 | 210 | *ptr = 0; | |
| 5575 |
1/2✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
|
210 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); |
| 5576 | 210 | return TYPE_WARN_OUT_OF_RANGE; | |
| 5577 | } | ||
| 5578 | |||
| 5579 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 5613 times.
|
5680 | if (conv_error) ret = TYPE_ERR_BAD_VALUE; |
| 5580 | |||
| 5581 |
3/4✓ Branch 0 taken 5680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4682 times.
✓ Branch 3 taken 998 times.
|
5680 | if (current_thd->check_for_truncated_fields) |
| 5582 |
1/2✓ Branch 0 taken 4682 times.
✗ Branch 1 not taken.
|
4682 | ret = check_int(cs, from, len, end, conv_error); |
| 5583 | |||
| 5584 |
2/2✓ Branch 0 taken 632 times.
✓ Branch 1 taken 5048 times.
|
5680 | if (ret != TYPE_OK) { |
| 5585 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 565 times.
|
632 | if (ret == TYPE_ERR_BAD_VALUE) /* empty or incorrect string */ |
| 5586 | { | ||
| 5587 | 67 | *ptr = 0; // Invalid date | |
| 5588 | 67 | return ret; | |
| 5589 | } | ||
| 5590 | 565 | ret = TYPE_WARN_OUT_OF_RANGE; | |
| 5591 | } | ||
| 5592 | |||
| 5593 |
4/4✓ Branch 0 taken 826 times.
✓ Branch 1 taken 4787 times.
✓ Branch 2 taken 95 times.
✓ Branch 3 taken 731 times.
|
5613 | if (nr != 0 || len != 4) { |
| 5594 |
2/2✓ Branch 0 taken 751 times.
✓ Branch 1 taken 4131 times.
|
4882 | if (nr < YY_PART_YEAR) |
| 5595 | 751 | nr += 100; // 2000 - 2069 | |
| 5596 |
2/2✓ Branch 0 taken 3912 times.
✓ Branch 1 taken 219 times.
|
4131 | else if (nr > 1900) |
| 5597 | 3912 | nr -= 1900; | |
| 5598 | } | ||
| 5599 | 5613 | *ptr = (char)(uchar)nr; | |
| 5600 | 5613 | return ret; | |
| 5601 | } | ||
| 5602 | |||
| 5603 | 302 | type_conversion_status Field_year::store(double nr) { | |
| 5604 |
4/4✓ Branch 0 taken 278 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 206 times.
|
302 | if (nr < 0.0 || nr > MAX_YEAR) { |
| 5605 | 96 | Field_year::store(-1LL, false); | |
| 5606 | 96 | return TYPE_WARN_OUT_OF_RANGE; | |
| 5607 | } | ||
| 5608 | 206 | return Field_year::store(static_cast<longlong>(nr), false); | |
| 5609 | } | ||
| 5610 | |||
| 5611 | 56 | type_conversion_status Field_year::store_time(MYSQL_TIME *ltime, uint8) { | |
| 5612 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 45 times.
|
56 | if (ltime->time_type != MYSQL_TIMESTAMP_DATETIME && |
| 5613 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 8 times.
|
11 | ltime->time_type != MYSQL_TIMESTAMP_DATE) { |
| 5614 | /* Convert time to datetime, then store year of the result */ | ||
| 5615 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | THD *thd = current_thd; |
| 5616 | MYSQL_TIME ltime2; | ||
| 5617 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | time_to_datetime(thd, ltime, <ime2); |
| 5618 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | return store(ltime2.year, false); |
| 5619 | } | ||
| 5620 | 53 | return store(ltime->year, false); | |
| 5621 | } | ||
| 5622 | |||
| 5623 | 5886 | type_conversion_status Field_year::store(longlong nr, bool) { | |
| 5624 |
4/6✓ Branch 0 taken 5886 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5855 times.
✓ Branch 3 taken 31 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5855 times.
|
5886 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 5625 |
8/8✓ Branch 0 taken 5756 times.
✓ Branch 1 taken 130 times.
✓ Branch 2 taken 4761 times.
✓ Branch 3 taken 995 times.
✓ Branch 4 taken 4587 times.
✓ Branch 5 taken 174 times.
✓ Branch 6 taken 150 times.
✓ Branch 7 taken 5432 times.
|
5886 | if (nr < 0 || (nr >= 100 && nr < MIN_YEAR) || nr > MAX_YEAR) { |
| 5626 | 454 | *ptr = 0; | |
| 5627 | 454 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 5628 | 454 | return TYPE_WARN_OUT_OF_RANGE; | |
| 5629 | } | ||
| 5630 |
2/2✓ Branch 0 taken 5240 times.
✓ Branch 1 taken 192 times.
|
5432 | if (nr != 0) // 0000 -> 0 |
| 5631 | { | ||
| 5632 |
2/2✓ Branch 0 taken 617 times.
✓ Branch 1 taken 4623 times.
|
5240 | if (nr < YY_PART_YEAR) |
| 5633 | 617 | nr += 100; // 2000 - 2069 | |
| 5634 |
2/2✓ Branch 0 taken 4437 times.
✓ Branch 1 taken 186 times.
|
4623 | else if (nr > 1900) |
| 5635 | 4437 | nr -= 1900; | |
| 5636 | } | ||
| 5637 | 5432 | *ptr = (char)(uchar)nr; | |
| 5638 | 5432 | return TYPE_OK; | |
| 5639 | } | ||
| 5640 | |||
| 5641 | 15842 | bool Field_year::send_to_protocol(Protocol *protocol) const { | |
| 5642 |
3/6✓ Branch 0 taken 15842 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15842 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15842 times.
|
15842 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5643 |
2/2✓ Branch 0 taken 528 times.
✓ Branch 1 taken 15314 times.
|
15842 | if (is_null()) return protocol->store_null(); |
| 5644 | // YEAR is always ZEROFILL. Always zero-pad values up to 4 digits. | ||
| 5645 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15314 times.
|
15314 | assert(zerofill); |
| 5646 | 15314 | ulonglong tmp = Field_year::val_int(); | |
| 5647 | 15314 | return protocol->store_short(tmp, field_length); | |
| 5648 | } | ||
| 5649 | |||
| 5650 | 925 | double Field_year::val_real() const { return (double)Field_year::val_int(); } | |
| 5651 | |||
| 5652 | 38460 | longlong Field_year::val_int() const { | |
| 5653 |
4/6✓ Branch 0 taken 38460 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38326 times.
✓ Branch 3 taken 134 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 38326 times.
|
38460 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5654 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38460 times.
|
38460 | assert(field_length == 4); |
| 5655 | 38460 | int tmp = (int)ptr[0]; | |
| 5656 |
2/2✓ Branch 0 taken 35309 times.
✓ Branch 1 taken 3151 times.
|
38460 | if (tmp != 0) tmp += 1900; |
| 5657 | 38460 | return (longlong)tmp; | |
| 5658 | } | ||
| 5659 | |||
| 5660 | 3502 | String *Field_year::val_str(String *val_buffer, String *) const { | |
| 5661 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3502 times.
|
3502 | assert(field_length == 4); |
| 5662 | 3502 | val_buffer->length(0); | |
| 5663 | 3502 | const longlong year = val_int(); | |
| 5664 | // YEAR is always ZEROFILL. Always zero-pad values up to 4 digits. | ||
| 5665 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3502 times.
|
3502 | assert(zerofill); |
| 5666 |
2/2✓ Branch 0 taken 392 times.
✓ Branch 1 taken 3110 times.
|
3502 | if (year == 0) |
| 5667 | 392 | val_buffer->fill(field_length, '0'); | |
| 5668 | else // If year != 0, year is always 4 digits | ||
| 5669 | 3110 | val_buffer->append_longlong(year); | |
| 5670 | 3502 | val_buffer->set_charset(&my_charset_numeric); | |
| 5671 | 3502 | return val_buffer; | |
| 5672 | } | ||
| 5673 | |||
| 5674 | 3744 | void Field_year::sql_type(String &res) const { | |
| 5675 | 3744 | res.length(0); | |
| 5676 | 3744 | res.append(STRING_WITH_LEN("year")); | |
| 5677 | 3744 | } | |
| 5678 | |||
| 5679 | /**************************************************************************** | ||
| 5680 | ** The new date type | ||
| 5681 | ** Stored as 3 bytes | ||
| 5682 | ** In number context: YYYYMMDD | ||
| 5683 | ****************************************************************************/ | ||
| 5684 | |||
| 5685 | 399071 | my_time_flags_t Field_newdate::date_flags(const THD *thd) const { | |
| 5686 | 399071 | my_time_flags_t date_flags = TIME_FUZZY_DATE; | |
| 5687 |
2/2✓ Branch 0 taken 371003 times.
✓ Branch 1 taken 28068 times.
|
399071 | if (thd->variables.sql_mode & MODE_NO_ZERO_DATE) |
| 5688 | 371003 | date_flags |= TIME_NO_ZERO_DATE; | |
| 5689 |
2/2✓ Branch 0 taken 371150 times.
✓ Branch 1 taken 27921 times.
|
399071 | if (thd->variables.sql_mode & MODE_NO_ZERO_IN_DATE) |
| 5690 | 371150 | date_flags |= TIME_NO_ZERO_IN_DATE; | |
| 5691 |
2/2✓ Branch 0 taken 6056 times.
✓ Branch 1 taken 393015 times.
|
399071 | if (thd->variables.sql_mode & MODE_INVALID_DATES) |
| 5692 | 6056 | date_flags |= TIME_INVALID_DATES; | |
| 5693 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 399071 times.
|
399071 | if (thd->variables.sql_mode & MODE_TIME_TRUNCATE_FRACTIONAL) |
| 5694 | ✗ | date_flags |= TIME_FRAC_TRUNCATE; | |
| 5695 | |||
| 5696 | 399071 | return date_flags; | |
| 5697 | } | ||
| 5698 | |||
| 5699 | 199026 | type_conversion_status Field_newdate::store_internal(const MYSQL_TIME *ltime, | |
| 5700 | int *warnings) { | ||
| 5701 | /* | ||
| 5702 | If time zone displacement information is present in "ltime" | ||
| 5703 | - adjust the value to UTC based on the time zone | ||
| 5704 | - convert to the local time zone | ||
| 5705 | */ | ||
| 5706 | MYSQL_TIME temp_time; | ||
| 5707 | const MYSQL_TIME *time; | ||
| 5708 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 199025 times.
|
199026 | if (ltime->time_type == MYSQL_TIMESTAMP_DATETIME_TZ) { |
| 5709 | 1 | temp_time = *ltime; | |
| 5710 | 1 | time = &temp_time; | |
| 5711 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | if (convert_time_zone_displacement(current_thd->time_zone(), &temp_time)) |
| 5712 | ✗ | return TYPE_ERR_BAD_VALUE; | |
| 5713 | } else { | ||
| 5714 | 199025 | time = ltime; | |
| 5715 | } | ||
| 5716 | |||
| 5717 |
1/2✓ Branch 0 taken 199026 times.
✗ Branch 1 not taken.
|
199026 | my_date_to_binary(time, ptr); |
| 5718 |
2/2✓ Branch 0 taken 1194 times.
✓ Branch 1 taken 197832 times.
|
199026 | if (non_zero_time(*ltime)) { |
| 5719 | 1194 | *warnings |= MYSQL_TIME_NOTE_TRUNCATED; | |
| 5720 | 1194 | return TYPE_NOTE_TIME_TRUNCATED; | |
| 5721 | } | ||
| 5722 | 197832 | return TYPE_OK; | |
| 5723 | } | ||
| 5724 | |||
| 5725 | 262871 | bool Field_newdate::get_date_internal(MYSQL_TIME *ltime) const { | |
| 5726 | 262871 | uint32 tmp = uint3korr(ptr); | |
| 5727 | 262871 | ltime->day = tmp & 31; | |
| 5728 | 262871 | ltime->month = (tmp >> 5) & 15; | |
| 5729 | 262871 | ltime->year = (tmp >> 9); | |
| 5730 | 262871 | ltime->time_type = MYSQL_TIMESTAMP_DATE; | |
| 5731 | 262871 | ltime->hour = ltime->minute = ltime->second = ltime->second_part = | |
| 5732 | 262871 | ltime->neg = false; | |
| 5733 | 262871 | ltime->time_zone_displacement = 0; | |
| 5734 | 262871 | return false; | |
| 5735 | } | ||
| 5736 | |||
| 5737 | 8 | type_conversion_status Field_newdate::store_packed(longlong nr) { | |
| 5738 | 8 | int warnings = 0; | |
| 5739 | MYSQL_TIME ltime; | ||
| 5740 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | TIME_from_longlong_date_packed(<ime, nr); |
| 5741 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
16 | return store_internal(<ime, &warnings); |
| 5742 | } | ||
| 5743 | |||
| 5744 | 43821 | bool Field_newdate::send_to_protocol(Protocol *protocol) const { | |
| 5745 |
4/6✓ Branch 0 taken 43821 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2271 times.
✓ Branch 3 taken 41550 times.
✓ Branch 4 taken 2271 times.
✗ Branch 5 not taken.
|
43821 | if (is_null()) return protocol->store_null(); |
| 5746 | MYSQL_TIME ltime; | ||
| 5747 |
1/2✓ Branch 0 taken 41550 times.
✗ Branch 1 not taken.
|
41550 | get_date(<ime, 0); |
| 5748 |
1/2✓ Branch 0 taken 41550 times.
✗ Branch 1 not taken.
|
41550 | return protocol->store_date(ltime); |
| 5749 | } | ||
| 5750 | |||
| 5751 | 238 | longlong Field_newdate::val_int() const { | |
| 5752 |
3/6✓ Branch 0 taken 238 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 238 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 238 times.
|
238 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5753 | 238 | ulong j = uint3korr(ptr); | |
| 5754 | 238 | j = (j % 32L) + (j / 32L % 16L) * 100L + (j / (16L * 32L)) * 10000L; | |
| 5755 | 238 | return (longlong)j; | |
| 5756 | } | ||
| 5757 | |||
| 5758 | 20581 | longlong Field_newdate::val_date_temporal() const { | |
| 5759 |
3/6✓ Branch 0 taken 20581 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20581 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 20581 times.
|
20581 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5760 | MYSQL_TIME ltime; | ||
| 5761 |
3/6✓ Branch 0 taken 20581 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20581 times.
✓ Branch 4 taken 20581 times.
✗ Branch 5 not taken.
|
20581 | return get_date_internal(<ime) ? 0 : TIME_to_longlong_date_packed(ltime); |
| 5762 | } | ||
| 5763 | |||
| 5764 | ✗ | longlong Field_newdate::val_time_temporal() const { | |
| 5765 | ✗ | ASSERT_COLUMN_MARKED_FOR_READ; | |
| 5766 | ✗ | return 0; | |
| 5767 | } | ||
| 5768 | |||
| 5769 | 7611 | String *Field_newdate::val_str(String *val_buffer, String *) const { | |
| 5770 |
4/6✓ Branch 0 taken 7611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7321 times.
✓ Branch 3 taken 290 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 7321 times.
|
7611 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5771 | 7611 | val_buffer->alloc(field_length); | |
| 5772 | 7611 | val_buffer->length(field_length); | |
| 5773 | 7611 | uint32 tmp = uint3korr(ptr); | |
| 5774 | int part; | ||
| 5775 | 7611 | char *pos = val_buffer->ptr() + 10; | |
| 5776 | |||
| 5777 | /* Open coded to get more speed */ | ||
| 5778 | 7611 | *pos-- = 0; // End NULL | |
| 5779 | 7611 | part = (int)(tmp & 31); | |
| 5780 | 7611 | *pos-- = (char)('0' + part % 10); | |
| 5781 | 7611 | *pos-- = (char)('0' + part / 10); | |
| 5782 | 7611 | *pos-- = '-'; | |
| 5783 | 7611 | part = (int)(tmp >> 5 & 15); | |
| 5784 | 7611 | *pos-- = (char)('0' + part % 10); | |
| 5785 | 7611 | *pos-- = (char)('0' + part / 10); | |
| 5786 | 7611 | *pos-- = '-'; | |
| 5787 | 7611 | part = (int)(tmp >> 9); | |
| 5788 | 7611 | *pos-- = (char)('0' + part % 10); | |
| 5789 | 7611 | part /= 10; | |
| 5790 | 7611 | *pos-- = (char)('0' + part % 10); | |
| 5791 | 7611 | part /= 10; | |
| 5792 | 7611 | *pos-- = (char)('0' + part % 10); | |
| 5793 | 7611 | part /= 10; | |
| 5794 | 7611 | *pos = (char)('0' + part); | |
| 5795 | 7611 | val_buffer->set_charset(&my_charset_numeric); | |
| 5796 | 7611 | return val_buffer; | |
| 5797 | } | ||
| 5798 | |||
| 5799 | 228309 | bool Field_newdate::get_date(MYSQL_TIME *ltime, | |
| 5800 | my_time_flags_t fuzzydate) const { | ||
| 5801 |
3/4✓ Branch 0 taken 228309 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2810 times.
✓ Branch 3 taken 225499 times.
|
456618 | return get_internal_check_zero(ltime, fuzzydate) || |
| 5802 | 456618 | check_fuzzy_date(*ltime, fuzzydate); | |
| 5803 | } | ||
| 5804 | |||
| 5805 | 5235 | int Field_newdate::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 5806 | uint32 a, b; | ||
| 5807 | 5235 | a = uint3korr(a_ptr); | |
| 5808 | 5235 | b = uint3korr(b_ptr); | |
| 5809 |
4/4✓ Branch 0 taken 2700 times.
✓ Branch 1 taken 2535 times.
✓ Branch 2 taken 1545 times.
✓ Branch 3 taken 1155 times.
|
5235 | return (a < b) ? -1 : (a > b) ? 1 : 0; |
| 5810 | } | ||
| 5811 | |||
| 5812 | 1291 | size_t Field_newdate::make_sort_key(uchar *to, size_t length) const { | |
| 5813 | 1291 | memset(to, 0, length); | |
| 5814 | 1291 | to[0] = ptr[2]; | |
| 5815 | 1291 | to[1] = ptr[1]; | |
| 5816 | 1291 | to[2] = ptr[0]; | |
| 5817 | 1291 | return 3; | |
| 5818 | } | ||
| 5819 | |||
| 5820 | 6749 | void Field_newdate::sql_type(String &res) const { | |
| 5821 | 6749 | res.set_ascii(STRING_WITH_LEN("date")); | |
| 5822 | 6749 | } | |
| 5823 | |||
| 5824 | /**************************************************************************** | ||
| 5825 | ** datetime type | ||
| 5826 | ** In string context: YYYY-MM-DD HH:MM:DD | ||
| 5827 | ** In number context: YYYYMMDDHHMMDD | ||
| 5828 | ** Stored as a 8 byte unsigned int. Should sometimes be change to a 6 byte int. | ||
| 5829 | ****************************************************************************/ | ||
| 5830 | |||
| 5831 | 228 | my_time_flags_t Field_datetime::date_flags(const THD *thd) const { | |
| 5832 | 228 | my_time_flags_t date_flags = TIME_FUZZY_DATE; | |
| 5833 |
2/2✓ Branch 0 taken 63 times.
✓ Branch 1 taken 165 times.
|
228 | if (thd->variables.sql_mode & MODE_NO_ZERO_DATE) |
| 5834 | 63 | date_flags |= TIME_NO_ZERO_DATE; | |
| 5835 |
2/2✓ Branch 0 taken 54 times.
✓ Branch 1 taken 174 times.
|
228 | if (thd->variables.sql_mode & MODE_NO_ZERO_IN_DATE) |
| 5836 | 54 | date_flags |= TIME_NO_ZERO_IN_DATE; | |
| 5837 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
|
228 | if (thd->variables.sql_mode & MODE_INVALID_DATES) |
| 5838 | ✗ | date_flags |= TIME_INVALID_DATES; | |
| 5839 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
|
228 | if (thd->variables.sql_mode & MODE_TIME_TRUNCATE_FRACTIONAL) |
| 5840 | ✗ | date_flags |= TIME_FRAC_TRUNCATE; | |
| 5841 | |||
| 5842 | 228 | return date_flags; | |
| 5843 | } | ||
| 5844 | |||
| 5845 | 3 | void Field_datetime::store_timestamp_internal(const my_timeval *tm) { | |
| 5846 | MYSQL_TIME mysql_time; | ||
| 5847 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | THD *thd = current_thd; |
| 5848 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | thd->variables.time_zone->gmt_sec_to_TIME(&mysql_time, *tm); |
| 5849 | 3 | thd->time_zone_used = true; | |
| 5850 | 3 | int error = 0; | |
| 5851 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | store_internal(&mysql_time, &error); |
| 5852 | 3 | } | |
| 5853 | |||
| 5854 | /** | ||
| 5855 | Store a DATETIME in a 8-byte integer to record. | ||
| 5856 | |||
| 5857 | @param table Table | ||
| 5858 | @param tmp The number, in YYYYMMDDhhmmss format | ||
| 5859 | @param ptr Where to store to | ||
| 5860 | */ | ||
| 5861 | 93 | static inline type_conversion_status datetime_store_internal(TABLE *table, | |
| 5862 | ulonglong tmp, | ||
| 5863 | uchar *ptr) { | ||
| 5864 |
2/4✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✗ Branch 3 not taken.
|
93 | if (table && table->s->db_low_byte_first) |
| 5865 | 93 | int8store(ptr, tmp); | |
| 5866 | else | ||
| 5867 | ✗ | longlongstore(ptr, tmp); | |
| 5868 | 93 | return TYPE_OK; | |
| 5869 | } | ||
| 5870 | |||
| 5871 | /** | ||
| 5872 | Read a DATETIME from record to a 8-byte integer | ||
| 5873 | |||
| 5874 | @param table Table | ||
| 5875 | @param ptr Where to read from | ||
| 5876 | @retval An integer in format YYYYMMDDhhmmss | ||
| 5877 | */ | ||
| 5878 | 141 | static inline longlong datetime_get_internal(TABLE *table, uchar *ptr) { | |
| 5879 |
2/4✓ Branch 0 taken 141 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 141 times.
✗ Branch 3 not taken.
|
141 | if (table && table->s->db_low_byte_first) |
| 5880 | 141 | return sint8korr(ptr); | |
| 5881 | else | ||
| 5882 | ✗ | return longlongget(ptr); | |
| 5883 | } | ||
| 5884 | |||
| 5885 | 3 | bool Field_datetime::get_date_internal(MYSQL_TIME *ltime) const { | |
| 5886 | 3 | longlong tmp = datetime_get_internal(table, ptr); | |
| 5887 | 3 | ltime->time_type = MYSQL_TIMESTAMP_DATETIME; | |
| 5888 | 3 | ltime->neg = false; | |
| 5889 | 3 | ltime->second_part = 0; | |
| 5890 | 3 | TIME_set_yymmdd(ltime, (uint)(tmp / 1000000LL)); | |
| 5891 | 3 | TIME_set_hhmmss(ltime, (uint)(tmp % 1000000LL)); | |
| 5892 | 3 | ltime->time_zone_displacement = 0; | |
| 5893 | 3 | return false; | |
| 5894 | } | ||
| 5895 | |||
| 5896 | 93 | type_conversion_status Field_datetime::store_internal(const MYSQL_TIME *ltime, | |
| 5897 | int *) { | ||
| 5898 | 93 | ulonglong tmp = TIME_to_ulonglong_datetime(*ltime); | |
| 5899 | 93 | return datetime_store_internal(table, tmp, ptr); | |
| 5900 | } | ||
| 5901 | |||
| 5902 | ✗ | type_conversion_status Field_datetime::store(longlong nr, bool unsigned_val) { | |
| 5903 | ✗ | ASSERT_COLUMN_MARKED_FOR_WRITE; | |
| 5904 | MYSQL_TIME ltime; | ||
| 5905 | int warnings; | ||
| 5906 | ✗ | type_conversion_status error = TYPE_OK; | |
| 5907 | longlong tmp = | ||
| 5908 | ✗ | convert_number_to_datetime(nr, unsigned_val, <ime, &warnings); | |
| 5909 | ✗ | if (tmp == -1LL) | |
| 5910 | ✗ | error = TYPE_ERR_BAD_VALUE; | |
| 5911 | else { | ||
| 5912 | ✗ | error = time_warning_to_type_conversion_status(warnings); | |
| 5913 | ✗ | datetime_store_internal(table, tmp, ptr); | |
| 5914 | } | ||
| 5915 | ✗ | if (warnings && set_warnings(ErrConvString(nr, unsigned_val), warnings)) | |
| 5916 | ✗ | error = TYPE_ERR_BAD_VALUE; | |
| 5917 | ✗ | return error; | |
| 5918 | } | ||
| 5919 | |||
| 5920 | ✗ | type_conversion_status Field_datetime::store_packed(longlong nr) { | |
| 5921 | MYSQL_TIME ltime; | ||
| 5922 | ✗ | TIME_from_longlong_datetime_packed(<ime, nr); | |
| 5923 | ✗ | return Field_datetime::store_time(<ime, 0); | |
| 5924 | } | ||
| 5925 | |||
| 5926 | ✗ | longlong Field_datetime::val_int() const { | |
| 5927 | ✗ | ASSERT_COLUMN_MARKED_FOR_READ; | |
| 5928 | ✗ | return datetime_get_internal(table, ptr); | |
| 5929 | } | ||
| 5930 | |||
| 5931 | /* | ||
| 5932 | We don't reuse the parent method for performance purposes, | ||
| 5933 | to avoid conversion from number to MYSQL_TIME. | ||
| 5934 | Using my_datetime_number_to_str() instead of my_datetime_to_str(). | ||
| 5935 | */ | ||
| 5936 | 138 | String *Field_datetime::val_str(String *val_buffer, String *) const { | |
| 5937 |
3/6✓ Branch 0 taken 138 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 138 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 138 times.
|
138 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 5938 | 138 | val_buffer->alloc(field_length + 1); | |
| 5939 | 138 | val_buffer->set_charset(&my_charset_numeric); | |
| 5940 | 138 | val_buffer->length(MAX_DATETIME_WIDTH); | |
| 5941 | 138 | longlong tmp = datetime_get_internal(table, ptr); | |
| 5942 | 138 | val_buffer->length(my_datetime_number_to_str(val_buffer->ptr(), tmp)); | |
| 5943 | 138 | return val_buffer; | |
| 5944 | } | ||
| 5945 | |||
| 5946 | 3 | bool Field_datetime::get_date(MYSQL_TIME *ltime, | |
| 5947 | my_time_flags_t fuzzydate) const { | ||
| 5948 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
6 | return get_internal_check_zero(ltime, fuzzydate) || |
| 5949 | 6 | check_fuzzy_date(*ltime, fuzzydate); | |
| 5950 | } | ||
| 5951 | |||
| 5952 | ✗ | int Field_datetime::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 5953 | longlong a, b; | ||
| 5954 | ✗ | if (table && table->s->db_low_byte_first) { | |
| 5955 | ✗ | a = sint8korr(a_ptr); | |
| 5956 | ✗ | b = sint8korr(b_ptr); | |
| 5957 | } else { | ||
| 5958 | ✗ | a = longlongget(a_ptr); | |
| 5959 | ✗ | b = longlongget(b_ptr); | |
| 5960 | } | ||
| 5961 | ✗ | return ((ulonglong)a < (ulonglong)b) ? -1 | |
| 5962 | ✗ | : ((ulonglong)a > (ulonglong)b) ? 1 : 0; | |
| 5963 | } | ||
| 5964 | |||
| 5965 | 6 | size_t Field_datetime::make_sort_key(uchar *to, size_t length) const { | |
| 5966 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | assert(length == PACK_LENGTH); |
| 5967 | #ifdef WORDS_BIGENDIAN | ||
| 5968 | if (!table || !table->s->db_low_byte_first) | ||
| 5969 | copy_integer<true>(to, length, ptr, PACK_LENGTH, true); | ||
| 5970 | else | ||
| 5971 | #endif | ||
| 5972 | 6 | copy_integer<false>(to, length, ptr, PACK_LENGTH, true); | |
| 5973 | 6 | return PACK_LENGTH; | |
| 5974 | } | ||
| 5975 | |||
| 5976 | 26905 | void Field_datetime::sql_type(String &res) const { | |
| 5977 | 26905 | res.set_ascii(STRING_WITH_LEN("datetime")); | |
| 5978 | 26905 | } | |
| 5979 | |||
| 5980 | /**************************************************************************** | ||
| 5981 | ** datetimef type | ||
| 5982 | ** In string context: YYYY-MM-DD HH:MM:DD.FFFFFF | ||
| 5983 | ** In number context: YYYYMMDDHHMMDD.FFFFFF | ||
| 5984 | ** Stored as a 8 byte value. | ||
| 5985 | ****************************************************************************/ | ||
| 5986 | |||
| 5987 | 5649826 | my_time_flags_t Field_datetimef::date_flags(const THD *thd) const { | |
| 5988 | 5649826 | my_time_flags_t date_flags = TIME_FUZZY_DATE; | |
| 5989 |
2/2✓ Branch 0 taken 5565822 times.
✓ Branch 1 taken 84004 times.
|
5649826 | if (thd->variables.sql_mode & MODE_NO_ZERO_DATE) |
| 5990 | 5565822 | date_flags |= TIME_NO_ZERO_DATE; | |
| 5991 |
2/2✓ Branch 0 taken 5565864 times.
✓ Branch 1 taken 83962 times.
|
5649826 | if (thd->variables.sql_mode & MODE_NO_ZERO_IN_DATE) |
| 5992 | 5565864 | date_flags |= TIME_NO_ZERO_IN_DATE; | |
| 5993 |
2/2✓ Branch 0 taken 5312 times.
✓ Branch 1 taken 5644514 times.
|
5649826 | if (thd->variables.sql_mode & MODE_INVALID_DATES) |
| 5994 | 5312 | date_flags |= TIME_INVALID_DATES; | |
| 5995 |
2/2✓ Branch 0 taken 458 times.
✓ Branch 1 taken 5649368 times.
|
5649826 | if (thd->variables.sql_mode & MODE_TIME_TRUNCATE_FRACTIONAL) |
| 5996 | 458 | date_flags |= TIME_FRAC_TRUNCATE; | |
| 5997 | |||
| 5998 | 5649826 | return date_flags; | |
| 5999 | } | ||
| 6000 | |||
| 6001 | 256 | void Field_datetimef::store_timestamp_internal(const my_timeval *tm) { | |
| 6002 | MYSQL_TIME mysql_time; | ||
| 6003 |
1/2✓ Branch 0 taken 256 times.
✗ Branch 1 not taken.
|
256 | THD *thd = current_thd; |
| 6004 |
1/2✓ Branch 0 taken 256 times.
✗ Branch 1 not taken.
|
256 | thd->variables.time_zone->gmt_sec_to_TIME(&mysql_time, *tm); |
| 6005 | 256 | thd->time_zone_used = true; | |
| 6006 | 256 | int warnings = 0; | |
| 6007 |
1/2✓ Branch 0 taken 256 times.
✗ Branch 1 not taken.
|
256 | store_internal(&mysql_time, &warnings); |
| 6008 | 256 | } | |
| 6009 | |||
| 6010 | 154087 | bool Field_datetimef::get_date(MYSQL_TIME *ltime, | |
| 6011 | my_time_flags_t fuzzydate) const { | ||
| 6012 |
3/4✓ Branch 0 taken 154087 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5488 times.
✓ Branch 3 taken 148598 times.
|
308173 | return get_internal_check_zero(ltime, fuzzydate) || |
| 6013 | 308173 | check_fuzzy_date(*ltime, fuzzydate); | |
| 6014 | } | ||
| 6015 | |||
| 6016 | 93470 | void Field_datetimef::sql_type(String &res) const { | |
| 6017 |
2/2✓ Branch 0 taken 91701 times.
✓ Branch 1 taken 1769 times.
|
93470 | if (dec == 0) { |
| 6018 | 91701 | res.set_ascii(STRING_WITH_LEN("datetime")); | |
| 6019 | 91701 | return; | |
| 6020 | } | ||
| 6021 | 1769 | const CHARSET_INFO *cs = res.charset(); | |
| 6022 | 1769 | res.length(cs->cset->snprintf(cs, res.ptr(), res.alloced_length(), | |
| 6023 | 1769 | "datetime(%d)", dec)); | |
| 6024 | } | ||
| 6025 | |||
| 6026 | 622773 | bool Field_datetimef::get_date_internal(MYSQL_TIME *ltime) const { | |
| 6027 | 622773 | TIME_from_longlong_datetime_packed(ltime, val_date_temporal()); | |
| 6028 | 622774 | return false; | |
| 6029 | } | ||
| 6030 | |||
| 6031 | 2824873 | type_conversion_status Field_datetimef::store_internal(const MYSQL_TIME *ltime, | |
| 6032 | int *) { | ||
| 6033 | /* | ||
| 6034 | If time zone displacement information is present in "ltime" | ||
| 6035 | - adjust the value to UTC based on the time zone | ||
| 6036 | - convert to the local time zone | ||
| 6037 | */ | ||
| 6038 | 2824873 | MYSQL_TIME temp_t = *ltime; | |
| 6039 |
3/6✓ Branch 0 taken 2824873 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2824872 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2824872 times.
|
2824873 | if (convert_time_zone_displacement(current_thd->time_zone(), &temp_t)) |
| 6040 | ✗ | return TYPE_ERR_BAD_VALUE; | |
| 6041 |
2/4✓ Branch 0 taken 2824877 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2824873 times.
✗ Branch 3 not taken.
|
2824872 | store_packed(TIME_to_longlong_datetime_packed(temp_t)); |
| 6042 | |||
| 6043 | 2824873 | return TYPE_OK; | |
| 6044 | } | ||
| 6045 | |||
| 6046 | 489110 | type_conversion_status Field_datetimef::reset() { | |
| 6047 | 489110 | store_packed(0); | |
| 6048 | 489110 | return TYPE_OK; | |
| 6049 | } | ||
| 6050 | |||
| 6051 | 670002 | longlong Field_datetimef::val_date_temporal() const { | |
| 6052 | 670002 | return my_datetime_packed_from_binary(ptr, dec); | |
| 6053 | } | ||
| 6054 | |||
| 6055 | 3314067 | type_conversion_status Field_datetimef::store_packed(longlong nr) { | |
| 6056 | 3314067 | my_datetime_packed_to_binary(nr, ptr, dec); | |
| 6057 | 3314066 | return TYPE_OK; | |
| 6058 | } | ||
| 6059 | |||
| 6060 | /**************************************************************************** | ||
| 6061 | ** string type | ||
| 6062 | ** A string may be varchar or binary | ||
| 6063 | ****************************************************************************/ | ||
| 6064 | |||
| 6065 | /** | ||
| 6066 | Report "not well formed" or "cannot convert" error | ||
| 6067 | after storing a character string info a field. | ||
| 6068 | |||
| 6069 | As of version 5.0 both cases return the same error: | ||
| 6070 | |||
| 6071 | "Invalid string value: 'xxx' for column 't' at row 1" | ||
| 6072 | |||
| 6073 | Future versions will possibly introduce a new error message: | ||
| 6074 | |||
| 6075 | "Cannot convert character string: 'xxx' for column 't' at row 1" | ||
| 6076 | |||
| 6077 | @param well_formed_error_pos position of the first non-wellformed | ||
| 6078 | character in the source string | ||
| 6079 | @param cannot_convert_error_pos position of the first non-convertable | ||
| 6080 | character in the source string | ||
| 6081 | @param from_end_pos position where conversion stopped in | ||
| 6082 | the source string | ||
| 6083 | @param end end of the source string | ||
| 6084 | @param count_spaces treat trailing spaces as important data | ||
| 6085 | @param cs character set of the string | ||
| 6086 | |||
| 6087 | @return TYPE_OK, TYPE_NOTE_TRUNCATED, TYPE_WARN_TRUNCATED, | ||
| 6088 | TYPE_WARN_INVALID_STRING | ||
| 6089 | |||
| 6090 | */ | ||
| 6091 | |||
| 6092 | 776699877 | type_conversion_status Field_longstr::check_string_copy_error( | |
| 6093 | const char *well_formed_error_pos, const char *cannot_convert_error_pos, | ||
| 6094 | const char *from_end_pos, const char *end, bool count_spaces, | ||
| 6095 | const CHARSET_INFO *cs) { | ||
| 6096 | const char *pos; | ||
| 6097 | char tmp[32]; | ||
| 6098 |
1/2✓ Branch 0 taken 776700453 times.
✗ Branch 1 not taken.
|
776699877 | THD *thd = current_thd; |
| 6099 | |||
| 6100 |
6/6✓ Branch 0 taken 776485113 times.
✓ Branch 1 taken 215340 times.
✓ Branch 2 taken 776476720 times.
✓ Branch 3 taken 8393 times.
✓ Branch 4 taken 776476814 times.
✓ Branch 5 taken 223639 times.
|
776700453 | if (!(pos = well_formed_error_pos) && !(pos = cannot_convert_error_pos)) |
| 6101 |
1/2✓ Branch 0 taken 776476562 times.
✗ Branch 1 not taken.
|
776476814 | return report_if_important_data(from_end_pos, end, count_spaces); |
| 6102 | |||
| 6103 |
1/2✓ Branch 0 taken 223777 times.
✗ Branch 1 not taken.
|
223643 | convert_to_printable(tmp, sizeof(tmp), pos, (end - pos), cs, 6); |
| 6104 | |||
| 6105 |
2/4✓ Branch 0 taken 223777 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 223777 times.
✗ Branch 3 not taken.
|
223777 | push_warning_printf( |
| 6106 | thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, | ||
| 6107 | ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), "string", tmp, | ||
| 6108 | field_name, thd->get_stmt_da()->current_row_for_condition()); | ||
| 6109 | |||
| 6110 |
2/2✓ Branch 0 taken 215478 times.
✓ Branch 1 taken 8299 times.
|
223777 | if (well_formed_error_pos != nullptr) return TYPE_WARN_INVALID_STRING; |
| 6111 | |||
| 6112 | 8299 | return TYPE_WARN_TRUNCATED; | |
| 6113 | } | ||
| 6114 | |||
| 6115 | /* | ||
| 6116 | Check if we lost any important data and send a truncation error/warning | ||
| 6117 | |||
| 6118 | SYNOPSIS | ||
| 6119 | Field_longstr::report_if_important_data() | ||
| 6120 | pstr - Truncated rest of string | ||
| 6121 | end - End of truncated string | ||
| 6122 | count_spaces - Treat trailing spaces as important data | ||
| 6123 | |||
| 6124 | RETURN VALUES | ||
| 6125 | TYPE_OK - None was truncated | ||
| 6126 | != TYPE_OK - Some bytes were truncated | ||
| 6127 | |||
| 6128 | NOTE | ||
| 6129 | Check if we lost any important data (anything in a binary string, | ||
| 6130 | or any non-space in others). If only trailing spaces was lost, | ||
| 6131 | send a truncation note, otherwise send a truncation error. | ||
| 6132 | Silently ignore trailing spaces if the count_space parameter is false. | ||
| 6133 | */ | ||
| 6134 | |||
| 6135 | 776476120 | type_conversion_status Field_longstr::report_if_important_data( | |
| 6136 | const char *pstr, const char *end, bool count_spaces) { | ||
| 6137 |
2/2✓ Branch 0 taken 4961 times.
✓ Branch 1 taken 776471159 times.
|
776476120 | if (pstr < end) // String is truncated |
| 6138 | { | ||
| 6139 | 4961 | THD *thd = current_thd; | |
| 6140 | |||
| 6141 |
1/2✓ Branch 0 taken 4770 times.
✗ Branch 1 not taken.
|
4961 | if (test_if_important_data(field_charset, pstr, end)) { |
| 6142 | // Warning should only be written when check_for_truncated_fields is set | ||
| 6143 |
2/2✓ Branch 0 taken 3695 times.
✓ Branch 1 taken 1075 times.
|
4770 | if (thd->check_for_truncated_fields) { |
| 6144 |
6/6✓ Branch 0 taken 2151 times.
✓ Branch 1 taken 1544 times.
✓ Branch 2 taken 163 times.
✓ Branch 3 taken 1988 times.
✓ Branch 4 taken 163 times.
✓ Branch 5 taken 3532 times.
|
3695 | if (!thd->lex->is_ignore() && thd->is_strict_mode()) |
| 6145 | 163 | set_warning(Sql_condition::SL_WARNING, ER_DATA_TOO_LONG, 1); | |
| 6146 | else | ||
| 6147 | 3532 | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); | |
| 6148 | } | ||
| 6149 | 4770 | return TYPE_WARN_TRUNCATED; | |
| 6150 | ✗ | } else if (count_spaces) { | |
| 6151 | // If we lost only spaces then produce a NOTE, not a WARNING | ||
| 6152 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 119 times.
|
133 | if (thd->check_for_truncated_fields) { |
| 6153 | 14 | set_warning(Sql_condition::SL_NOTE, WARN_DATA_TRUNCATED, 1); | |
| 6154 | } | ||
| 6155 | 133 | return TYPE_NOTE_TRUNCATED; | |
| 6156 | } | ||
| 6157 | } | ||
| 6158 | 697503629 | return TYPE_OK; | |
| 6159 | } | ||
| 6160 | |||
| 6161 | /* Copy a string and fill with space */ | ||
| 6162 | |||
| 6163 | 133874304 | type_conversion_status Field_string::store(const char *from, size_t length, | |
| 6164 | const CHARSET_INFO *cs) { | ||
| 6165 |
4/6✓ Branch 0 taken 133874311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 133765485 times.
✓ Branch 3 taken 108826 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 133765574 times.
|
133874304 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 6166 | size_t copy_length; | ||
| 6167 | const char *well_formed_error_pos; | ||
| 6168 | const char *cannot_convert_error_pos; | ||
| 6169 | const char *from_end_pos; | ||
| 6170 | |||
| 6171 | 267748870 | copy_length = field_well_formed_copy_nchars( | |
| 6172 | 133874393 | field_charset, (char *)ptr, field_length, cs, from, length, | |
| 6173 |
1/2✓ Branch 0 taken 133874477 times.
✗ Branch 1 not taken.
|
133874393 | field_length / field_charset->mbmaxlen, &well_formed_error_pos, |
| 6174 | &cannot_convert_error_pos, &from_end_pos); | ||
| 6175 | |||
| 6176 | /* Append spaces if the string was shorter than the field. */ | ||
| 6177 |
2/2✓ Branch 0 taken 91749589 times.
✓ Branch 1 taken 42124888 times.
|
133874477 | if (copy_length < field_length) |
| 6178 | 91749589 | field_charset->cset->fill(field_charset, (char *)ptr + copy_length, | |
| 6179 | 91749589 | field_length - copy_length, | |
| 6180 |
1/2✓ Branch 0 taken 91749503 times.
✗ Branch 1 not taken.
|
91749589 | field_charset->pad_char); |
| 6181 | |||
| 6182 |
1/2✓ Branch 0 taken 133874400 times.
✗ Branch 1 not taken.
|
133874391 | return check_string_copy_error(well_formed_error_pos, |
| 6183 | cannot_convert_error_pos, from_end_pos, | ||
| 6184 | 267748800 | from + length, false, cs); | |
| 6185 | } | ||
| 6186 | |||
| 6187 | /** | ||
| 6188 | Store double value in Field_string or Field_varstring. | ||
| 6189 | |||
| 6190 | Pretty prints double number into field_length characters buffer. | ||
| 6191 | |||
| 6192 | @param nr number | ||
| 6193 | */ | ||
| 6194 | |||
| 6195 | 7051 | type_conversion_status Field_str::store(double nr) { | |
| 6196 |
3/6✓ Branch 0 taken 7051 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7051 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7051 times.
|
7051 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 6197 | char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE]; | ||
| 6198 |
1/2✓ Branch 0 taken 7051 times.
✗ Branch 1 not taken.
|
7051 | uint local_char_length = field_length / charset()->mbmaxlen; |
| 6199 | 7051 | size_t length = 0; | |
| 6200 | 7051 | bool error = (local_char_length == 0); | |
| 6201 | |||
| 6202 | // my_gcvt() requires width > 0, and we may have a CHAR(0) column. | ||
| 6203 |
2/2✓ Branch 0 taken 7050 times.
✓ Branch 1 taken 1 times.
|
7051 | if (!error) |
| 6204 |
1/2✓ Branch 0 taken 7050 times.
✗ Branch 1 not taken.
|
7050 | length = my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error); |
| 6205 | |||
| 6206 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 7013 times.
|
7051 | if (error) { |
| 6207 |
1/2✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
|
38 | THD *thd = current_thd; |
| 6208 | |||
| 6209 |
4/6✓ Branch 0 taken 37 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 37 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 38 times.
|
38 | if (!thd->lex->is_ignore() && thd->is_strict_mode()) |
| 6210 | ✗ | set_warning(Sql_condition::SL_WARNING, ER_DATA_TOO_LONG, 1); | |
| 6211 | else | ||
| 6212 |
1/2✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
|
38 | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); |
| 6213 | } | ||
| 6214 |
1/2✓ Branch 0 taken 7051 times.
✗ Branch 1 not taken.
|
14102 | return store(buff, length, &my_charset_numeric); |
| 6215 | } | ||
| 6216 | |||
| 6217 | /** | ||
| 6218 | Check whether generated columns' expressions are the same. | ||
| 6219 | |||
| 6220 | @param field A new field to compare against | ||
| 6221 | |||
| 6222 | @return true means the same, otherwise not. | ||
| 6223 | */ | ||
| 6224 | |||
| 6225 | 6273 | bool Field::gcol_expr_is_equal(const Create_field *field) const { | |
| 6226 |
2/4✓ Branch 0 taken 6273 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6273 times.
✗ Branch 3 not taken.
|
6273 | assert(is_gcol() && field->is_gcol()); |
| 6227 | 6273 | return gcol_info->expr_item->eq(field->gcol_info->expr_item, true); | |
| 6228 | } | ||
| 6229 | |||
| 6230 | 88877 | uint Field_str::is_equal(const Create_field *new_field) const { | |
| 6231 |
1/2✓ Branch 0 taken 88877 times.
✗ Branch 1 not taken.
|
88877 | DBUG_TRACE; |
| 6232 | |||
| 6233 |
3/4✓ Branch 0 taken 88877 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4406 times.
✓ Branch 3 taken 84471 times.
|
88877 | if (change_prevents_inplace(*this, *new_field)) { |
| 6234 | 4406 | return IS_EQUAL_NO; | |
| 6235 | } | ||
| 6236 | |||
| 6237 |
1/2✓ Branch 0 taken 84471 times.
✗ Branch 1 not taken.
|
84471 | size_t new_char_len = new_field->max_display_width_in_codepoints(); |
| 6238 |
3/4✓ Branch 0 taken 84471 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 104 times.
✓ Branch 3 taken 84367 times.
|
84471 | if (new_char_len != char_length() // Changed char len cannot be done |
| 6239 | // inplace due to padding | ||
| 6240 | ) { | ||
| 6241 | 104 | return IS_EQUAL_NO; | |
| 6242 | } | ||
| 6243 | |||
| 6244 |
2/2✓ Branch 0 taken 84037 times.
✓ Branch 1 taken 330 times.
|
84367 | if (new_field->charset == field_charset) { |
| 6245 | 84037 | return IS_EQUAL_YES; | |
| 6246 | } | ||
| 6247 | |||
| 6248 | 330 | return IS_EQUAL_PACK_LENGTH; | |
| 6249 | 88877 | } | |
| 6250 | |||
| 6251 | 247544 | type_conversion_status Field_string::store(longlong nr, bool unsigned_val) { | |
| 6252 | char buff[64]; | ||
| 6253 | size_t l; | ||
| 6254 |
1/2✓ Branch 0 taken 247544 times.
✗ Branch 1 not taken.
|
247544 | const CHARSET_INFO *cs = charset(); |
| 6255 |
3/4✓ Branch 0 taken 12 times.
✓ Branch 1 taken 247532 times.
✓ Branch 2 taken 247544 times.
✗ Branch 3 not taken.
|
247544 | l = (cs->cset->longlong10_to_str)(cs, buff, sizeof(buff), |
| 6256 | unsigned_val ? 10 : -10, nr); | ||
| 6257 |
1/2✓ Branch 0 taken 247544 times.
✗ Branch 1 not taken.
|
495088 | return Field_string::store(buff, l, cs); |
| 6258 | } | ||
| 6259 | |||
| 6260 | 585 | type_conversion_status Field_longstr::store_decimal(const my_decimal *d) { | |
| 6261 | 585 | StringBuffer<DECIMAL_MAX_STR_LENGTH + 1> str(&my_charset_numeric); | |
| 6262 |
1/2✓ Branch 0 taken 585 times.
✗ Branch 1 not taken.
|
585 | my_decimal2string(E_DEC_FATAL_ERROR, d, &str); |
| 6263 |
1/2✓ Branch 0 taken 585 times.
✗ Branch 1 not taken.
|
1170 | return store(str.ptr(), str.length(), str.charset()); |
| 6264 | 585 | } | |
| 6265 | |||
| 6266 | 161904458 | uint32 Field_longstr::max_data_length() const { | |
| 6267 |
2/2✓ Branch 0 taken 38995271 times.
✓ Branch 1 taken 122909187 times.
|
161904458 | return field_length + (field_length > 255 ? 2 : 1); |
| 6268 | } | ||
| 6269 | |||
| 6270 | 10266 | double Field_string::val_real() const { | |
| 6271 |
3/6✓ Branch 0 taken 10266 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10266 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10266 times.
|
10266 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 6272 | int error; | ||
| 6273 | const char *end; | ||
| 6274 |
1/2✓ Branch 0 taken 10266 times.
✗ Branch 1 not taken.
|
10266 | const CHARSET_INFO *cs = charset(); |
| 6275 | double result; | ||
| 6276 | |||
| 6277 |
1/2✓ Branch 0 taken 10266 times.
✗ Branch 1 not taken.
|
10266 | result = my_strntod(cs, (char *)ptr, field_length, &end, &error); |
| 6278 |
3/4✓ Branch 0 taken 10266 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 174 times.
✓ Branch 3 taken 10092 times.
|
20532 | if ((error || |
| 6279 |
2/2✓ Branch 0 taken 10243 times.
✓ Branch 1 taken 23 times.
|
10266 | (field_length != (uint32)(end - (char *)ptr) && |
| 6280 |
3/4✓ Branch 0 taken 10243 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 174 times.
✓ Branch 3 taken 10069 times.
|
10243 | !check_if_only_end_space(cs, end, (char *)ptr + field_length)))) { |
| 6281 | size_t length = | ||
| 6282 |
1/2✓ Branch 0 taken 174 times.
✗ Branch 1 not taken.
|
174 | cs->cset->lengthsp(cs, pointer_cast<const char *>(ptr), field_length); |
| 6283 |
1/2✓ Branch 0 taken 174 times.
✗ Branch 1 not taken.
|
174 | ErrConvString err((char *)ptr, length, cs); |
| 6284 | 174 | push_warning_printf( | |
| 6285 |
2/4✓ Branch 0 taken 174 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 174 times.
✗ Branch 3 not taken.
|
174 | current_thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE, |
| 6286 |
2/4✓ Branch 0 taken 174 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 174 times.
✗ Branch 3 not taken.
|
174 | ER_THD(current_thd, ER_TRUNCATED_WRONG_VALUE), "DOUBLE", err.ptr()); |
| 6287 | } | ||
| 6288 | 10266 | return result; | |
| 6289 | } | ||
| 6290 | |||
| 6291 | 57 | longlong Field_string::val_int() const { | |
| 6292 |
3/6✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 57 times.
|
57 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 6293 | int error; | ||
| 6294 | const char *end; | ||
| 6295 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | const CHARSET_INFO *cs = charset(); |
| 6296 | longlong result; | ||
| 6297 | |||
| 6298 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | result = my_strntoll(cs, (char *)ptr, field_length, 10, &end, &error); |
| 6299 |
4/4✓ Branch 0 taken 43 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 39 times.
|
100 | if ((error || |
| 6300 |
1/2✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
|
43 | (field_length != (uint32)(end - (char *)ptr) && |
| 6301 |
3/4✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 39 times.
|
43 | !check_if_only_end_space(cs, end, (char *)ptr + field_length)))) { |
| 6302 | size_t length = | ||
| 6303 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | cs->cset->lengthsp(cs, pointer_cast<const char *>(ptr), field_length); |
| 6304 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | ErrConvString err((char *)ptr, length, cs); |
| 6305 | 18 | push_warning_printf( | |
| 6306 |
2/4✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
18 | current_thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE, |
| 6307 |
2/4✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
18 | ER_THD(current_thd, ER_TRUNCATED_WRONG_VALUE), "INTEGER", err.ptr()); |
| 6308 | } | ||
| 6309 | 57 | return result; | |
| 6310 | } | ||
| 6311 | |||
| 6312 | 46065265 | String *Field_string::val_str(String *, String *val_ptr) const { | |
| 6313 |
4/6✓ Branch 0 taken 46065265 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45956812 times.
✓ Branch 3 taken 108453 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 45956812 times.
|
46065265 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 6314 | size_t length; | ||
| 6315 |
2/2✓ Branch 0 taken 3590950 times.
✓ Branch 1 taken 42474315 times.
|
46065265 | if (current_thd->variables.sql_mode & MODE_PAD_CHAR_TO_FULL_LENGTH) |
| 6316 | 3590950 | length = my_charpos(field_charset, ptr, ptr + field_length, | |
| 6317 | field_length / field_charset->mbmaxlen); | ||
| 6318 | else | ||
| 6319 | 42474315 | length = field_charset->cset->lengthsp(field_charset, (const char *)ptr, | |
| 6320 | 42474315 | field_length); | |
| 6321 | 46065265 | val_ptr->set((const char *)ptr, length, field_charset); | |
| 6322 | 46065265 | return val_ptr; | |
| 6323 | } | ||
| 6324 | |||
| 6325 | 72 | my_decimal *Field_string::val_decimal(my_decimal *decimal_value) const { | |
| 6326 |
3/6✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 72 times.
|
72 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 6327 | 72 | const CHARSET_INFO *cs = charset(); | |
| 6328 | 72 | int err = str2my_decimal(E_DEC_FATAL_ERROR, (char *)ptr, field_length, cs, | |
| 6329 | decimal_value); | ||
| 6330 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 16 times.
|
72 | if (err) { |
| 6331 | size_t length = | ||
| 6332 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | cs->cset->lengthsp(cs, pointer_cast<const char *>(ptr), field_length); |
| 6333 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | ErrConvString errmsg((char *)ptr, length, cs); |
| 6334 | 56 | push_warning_printf( | |
| 6335 |
2/4✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
|
56 | current_thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE, |
| 6336 |
2/4✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
|
56 | ER_THD(current_thd, ER_TRUNCATED_WRONG_VALUE), "DECIMAL", errmsg.ptr()); |
| 6337 | } | ||
| 6338 | |||
| 6339 | 72 | return decimal_value; | |
| 6340 | } | ||
| 6341 | |||
| 6342 | struct Check_field_param { | ||
| 6343 | const Field *field; | ||
| 6344 | }; | ||
| 6345 | |||
| 6346 | 5 | static bool check_field_for_37426(const void *param_arg) { | |
| 6347 | 5 | const Check_field_param *param = | |
| 6348 | static_cast<const Check_field_param *>(param_arg); | ||
| 6349 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | assert(param->field->real_type() == MYSQL_TYPE_STRING); |
| 6350 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | DBUG_PRINT("debug", |
| 6351 | ("Field %s - type: %d, size: %d", param->field->field_name, | ||
| 6352 | param->field->real_type(), param->field->row_pack_length())); | ||
| 6353 | 5 | return param->field->row_pack_length() > 255; | |
| 6354 | } | ||
| 6355 | |||
| 6356 | 57254 | bool Field_string::compatible_field_size(uint field_metadata, | |
| 6357 | Relay_log_info *rli_arg, uint16 mflags, | ||
| 6358 | int *order_var) const { | ||
| 6359 | 57254 | const Check_field_param check_param = {this}; | |
| 6360 |
4/4✓ Branch 0 taken 337 times.
✓ Branch 1 taken 56917 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 57253 times.
|
57591 | if (!is_mts_worker(rli_arg->info_thd) && |
| 6361 |
3/4✓ Branch 0 taken 337 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 336 times.
|
337 | rpl_master_has_bug(rli_arg, 37426, true, check_field_for_37426, |
| 6362 | &check_param)) | ||
| 6363 | 1 | return false; // Not compatible field sizes | |
| 6364 |
1/2✓ Branch 0 taken 57253 times.
✗ Branch 1 not taken.
|
57253 | return Field::compatible_field_size(field_metadata, rli_arg, mflags, |
| 6365 | 57253 | order_var); | |
| 6366 | } | ||
| 6367 | |||
| 6368 | 339526 | int Field_string::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 6369 | size_t a_len, b_len; | ||
| 6370 | |||
| 6371 |
2/2✓ Branch 0 taken 314542 times.
✓ Branch 1 taken 24984 times.
|
339526 | if (field_charset->mbmaxlen != 1) { |
| 6372 | 314542 | uint char_len = field_length / field_charset->mbmaxlen; | |
| 6373 | 314542 | a_len = my_charpos(field_charset, a_ptr, a_ptr + field_length, char_len); | |
| 6374 | 314542 | b_len = my_charpos(field_charset, b_ptr, b_ptr + field_length, char_len); | |
| 6375 | } else | ||
| 6376 | 24984 | a_len = b_len = field_length; | |
| 6377 | |||
| 6378 |
4/4✓ Branch 0 taken 189652 times.
✓ Branch 1 taken 149874 times.
✓ Branch 2 taken 189652 times.
✓ Branch 3 taken 149874 times.
|
529178 | if (field_charset->pad_attribute == NO_PAD && |
| 6379 |
1/2✓ Branch 0 taken 189652 times.
✗ Branch 1 not taken.
|
189652 | !(current_thd->variables.sql_mode & MODE_PAD_CHAR_TO_FULL_LENGTH)) { |
| 6380 | /* | ||
| 6381 | Our CHAR default behavior is to strip spaces. For PAD SPACE collations, | ||
| 6382 | this doesn't matter, for but NO PAD, we need to do it ourselves here. | ||
| 6383 | */ | ||
| 6384 | 189652 | a_len = field_charset->cset->lengthsp(field_charset, (const char *)a_ptr, | |
| 6385 | a_len); | ||
| 6386 | 189652 | b_len = field_charset->cset->lengthsp(field_charset, (const char *)b_ptr, | |
| 6387 | b_len); | ||
| 6388 | } | ||
| 6389 | |||
| 6390 | 339526 | return field_charset->coll->strnncollsp(field_charset, a_ptr, a_len, b_ptr, | |
| 6391 | 339526 | b_len); | |
| 6392 | } | ||
| 6393 | |||
| 6394 | 170413998 | size_t Field_string::make_sort_key(uchar *to, size_t length) const { | |
| 6395 | /* | ||
| 6396 | We don't store explicitly how many bytes long this string is. | ||
| 6397 | Find out by calling charpos, since just using field_length | ||
| 6398 | could give strnxfrm a buffer with more than char_length() code | ||
| 6399 | points, which is not allowed. | ||
| 6400 | |||
| 6401 | The min() is because charpos() is allowed to return a value past | ||
| 6402 | the end of the string for “end of string”. | ||
| 6403 | */ | ||
| 6404 | 170413998 | size_t input_length = std::min<size_t>( | |
| 6405 | 340827996 | field_length, | |
| 6406 | 170413998 | field_charset->cset->charpos( | |
| 6407 | 170413998 | field_charset, pointer_cast<const char *>(ptr), | |
| 6408 | 170413998 | pointer_cast<const char *>(ptr) + field_length, char_length())); | |
| 6409 | |||
| 6410 |
4/4✓ Branch 0 taken 123540 times.
✓ Branch 1 taken 170290458 times.
✓ Branch 2 taken 123540 times.
✓ Branch 3 taken 170290458 times.
|
170537538 | if (field_charset->pad_attribute == NO_PAD && |
| 6411 |
1/2✓ Branch 0 taken 123540 times.
✗ Branch 1 not taken.
|
123540 | !(current_thd->variables.sql_mode & MODE_PAD_CHAR_TO_FULL_LENGTH)) { |
| 6412 | /* | ||
| 6413 | Our CHAR default behavior is to strip spaces. For PAD SPACE collations, | ||
| 6414 | this doesn't matter, for but NO PAD, we need to do it ourselves here. | ||
| 6415 | */ | ||
| 6416 | 123540 | input_length = field_charset->cset->lengthsp( | |
| 6417 | 123540 | field_charset, (const char *)ptr, input_length); | |
| 6418 | } | ||
| 6419 | |||
| 6420 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 170413998 times.
|
170413998 | assert(char_length_cache == char_length()); |
| 6421 | 340827996 | size_t tmp [[maybe_unused]] = field_charset->coll->strnxfrm( | |
| 6422 | 170413998 | field_charset, to, length, char_length_cache, ptr, input_length, | |
| 6423 | MY_STRXFRM_PAD_TO_MAXLEN); | ||
| 6424 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 170413998 times.
|
170413998 | assert(tmp == length); |
| 6425 | 170413998 | return length; | |
| 6426 | } | ||
| 6427 | |||
| 6428 | 770923 | void Field_string::sql_type(String &res) const { | |
| 6429 | 770923 | THD *thd = current_thd; | |
| 6430 | 770923 | const CHARSET_INFO *cs = res.charset(); | |
| 6431 | size_t length; | ||
| 6432 | |||
| 6433 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 770923 times.
|
1541846 | length = cs->cset->snprintf( |
| 6434 | cs, res.ptr(), res.alloced_length(), "%s(%d)", | ||
| 6435 | ✗ | ((type() == MYSQL_TYPE_VAR_STRING && !thd->variables.new_mode) | |
| 6436 | ✗ | ? (has_charset() ? "varchar" : "varbinary") | |
| 6437 |
2/2✓ Branch 0 taken 753283 times.
✓ Branch 1 taken 17640 times.
|
770923 | : (has_charset() ? "char" : "binary")), |
| 6438 | 770923 | (int)field_length / charset()->mbmaxlen); | |
| 6439 | 770923 | res.length(length); | |
| 6440 | 770923 | } | |
| 6441 | |||
| 6442 | 150988712 | uchar *Field_string::pack(uchar *to, const uchar *from, | |
| 6443 | size_t max_length) const { | ||
| 6444 | 150988712 | uint length = my_charpos(field_charset, from, from + field_length, | |
| 6445 | field_length / field_charset->mbmaxlen); | ||
| 6446 |
2/2✓ Branch 0 taken 28131150 times.
✓ Branch 1 taken 122857566 times.
|
150988716 | uint length_bytes = (field_length > 255) ? 2 : 1; |
| 6447 | |||
| 6448 | /* | ||
| 6449 | TODO: change charset interface to add a new function that does | ||
| 6450 | the following or add a flag to lengthsp to do it itself | ||
| 6451 | (this is for not packing padding adding bytes in BINARY | ||
| 6452 | fields). | ||
| 6453 | */ | ||
| 6454 |
2/2✓ Branch 0 taken 112874224 times.
✓ Branch 1 taken 38114492 times.
|
150988716 | if (field_charset->mbmaxlen == 1) { |
| 6455 |
4/4✓ Branch 0 taken 1057948015 times.
✓ Branch 1 taken 24311 times.
✓ Branch 2 taken 945098102 times.
✓ Branch 3 taken 112849913 times.
|
1057972326 | while (length && from[length - 1] == field_charset->pad_char) length--; |
| 6456 | } else | ||
| 6457 | 38114492 | length = field_charset->cset->lengthsp(field_charset, (const char *)from, | |
| 6458 | length); | ||
| 6459 | |||
| 6460 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 150988712 times.
|
150988716 | if (max_length < length_bytes) |
| 6461 | 4 | length = 0; | |
| 6462 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 150988657 times.
|
150988712 | else if (length > max_length - length_bytes) |
| 6463 | 55 | length = max_length - length_bytes; | |
| 6464 | |||
| 6465 | /* Length always stored little-endian */ | ||
| 6466 |
2/2✓ Branch 0 taken 150988712 times.
✓ Branch 1 taken 4 times.
|
150988716 | if (max_length >= 1) { |
| 6467 | 150988712 | *to++ = length & 0xFF; | |
| 6468 |
3/4✓ Branch 0 taken 28131147 times.
✓ Branch 1 taken 122857565 times.
✓ Branch 2 taken 28131147 times.
✗ Branch 3 not taken.
|
150988712 | if (length_bytes == 2 && max_length >= 2) *to++ = (length >> 8) & 0xFF; |
| 6469 | } | ||
| 6470 | |||
| 6471 | /* Store bytes of string */ | ||
| 6472 | 150988716 | memcpy(to, from, length); | |
| 6473 | |||
| 6474 | 150988716 | return to + length; | |
| 6475 | } | ||
| 6476 | |||
| 6477 | /** | ||
| 6478 | Unpack a string field from row data. | ||
| 6479 | |||
| 6480 | This method is used to unpack a string field from a master whose size | ||
| 6481 | of the field is less than that of the slave. Note that there can be a | ||
| 6482 | variety of field types represented with this class. Certain types like | ||
| 6483 | ENUM or SET are processed differently. Hence, the upper byte of the | ||
| 6484 | @c param_data argument contains the result of field->real_type() from | ||
| 6485 | the master. | ||
| 6486 | |||
| 6487 | @note For information about how the length is packed, see @c | ||
| 6488 | Field_string::do_save_field_metadata | ||
| 6489 | |||
| 6490 | @param to Destination of the data | ||
| 6491 | @param from Source of the data | ||
| 6492 | @param param_data Real type (upper) and length (lower) values | ||
| 6493 | |||
| 6494 | @return New pointer into memory based on from + length of the data | ||
| 6495 | */ | ||
| 6496 | 7522595 | const uchar *Field_string::unpack(uchar *to, const uchar *from, | |
| 6497 | uint param_data) { | ||
| 6498 | uint from_length, length; | ||
| 6499 | |||
| 6500 | /* | ||
| 6501 | Compute the declared length of the field on the master. This is | ||
| 6502 | used to decide if one or two bytes should be read as length. | ||
| 6503 | */ | ||
| 6504 |
2/2✓ Branch 0 taken 108869 times.
✓ Branch 1 taken 7413726 times.
|
7522595 | if (param_data) |
| 6505 | 108869 | from_length = (((param_data >> 4) & 0x300) ^ 0x300) + (param_data & 0x00ff); | |
| 6506 | else | ||
| 6507 | 7413726 | from_length = field_length; | |
| 6508 | |||
| 6509 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7522595 times.
|
7522595 | DBUG_PRINT("debug", ("param_data: 0x%x, field_length: %u, from_length: %u", |
| 6510 | param_data, field_length, from_length)); | ||
| 6511 | /* | ||
| 6512 | Compute the actual length of the data by reading one or two bits | ||
| 6513 | (depending on the declared field length on the master). | ||
| 6514 | */ | ||
| 6515 |
2/2✓ Branch 0 taken 108096 times.
✓ Branch 1 taken 7414499 times.
|
7522595 | if (from_length > 255) { |
| 6516 | 108096 | length = uint2korr(from); | |
| 6517 | 108096 | from += 2; | |
| 6518 | } else | ||
| 6519 | 7414499 | length = (uint)*from++; | |
| 6520 | |||
| 6521 | 7522595 | memcpy(to, from, length); | |
| 6522 | // Pad the string with the pad character of the fields charset | ||
| 6523 | 7522595 | field_charset->cset->fill(field_charset, (char *)to + length, | |
| 6524 | 7522595 | field_length - length, field_charset->pad_char); | |
| 6525 | 7522595 | return from + length; | |
| 6526 | } | ||
| 6527 | |||
| 6528 | /** | ||
| 6529 | Save the field metadata for string fields. | ||
| 6530 | |||
| 6531 | Saves the real type in the first byte and the field length in the | ||
| 6532 | second byte of the field metadata array at index of *metadata_ptr and | ||
| 6533 | *(metadata_ptr + 1). | ||
| 6534 | |||
| 6535 | @note In order to be able to handle lengths exceeding 255 and be | ||
| 6536 | backwards-compatible with pre-5.1.26 servers, an extra two bits of | ||
| 6537 | the length has been added to the metadata in such a way that if | ||
| 6538 | they are set, a new unrecognized type is generated. This will | ||
| 6539 | cause pre-5.1-26 servers to stop due to a field type mismatch, | ||
| 6540 | while new servers will be able to extract the extra bits. If the | ||
| 6541 | length is <256, there will be no difference and both a new and an | ||
| 6542 | old server will be able to handle it. | ||
| 6543 | |||
| 6544 | @note The extra two bits are added to bits 13 and 14 of the | ||
| 6545 | parameter data (with 1 being the least siginficant bit and 16 the | ||
| 6546 | most significant bit of the word) by xoring the extra length bits | ||
| 6547 | with the real type. Since all allowable types have 0xF as most | ||
| 6548 | significant bits of the metadata word, lengths <256 will not affect | ||
| 6549 | the real type at all, while all other values will result in a | ||
| 6550 | non-existent type in the range 17-244. | ||
| 6551 | |||
| 6552 | @see Field_string::unpack | ||
| 6553 | |||
| 6554 | @param metadata_ptr First byte of field metadata | ||
| 6555 | |||
| 6556 | @returns number of bytes written to metadata_ptr | ||
| 6557 | */ | ||
| 6558 | 5228582 | int Field_string::do_save_field_metadata(uchar *metadata_ptr) const { | |
| 6559 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5228582 times.
|
5228582 | assert(field_length < 1024); |
| 6560 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5228582 times.
|
5228582 | assert((real_type() & 0xF0) == 0xF0); |
| 6561 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 5228536 times.
|
5228582 | DBUG_PRINT("debug", |
| 6562 | ("field_length: %u, real_type: %u", field_length, real_type())); | ||
| 6563 | 5228582 | *metadata_ptr = (real_type() ^ ((field_length & 0x300) >> 4)); | |
| 6564 | 5228582 | *(metadata_ptr + 1) = field_length & 0xFF; | |
| 6565 | 5228582 | return 2; | |
| 6566 | } | ||
| 6567 | |||
| 6568 | 219868 | uint Field_string::max_packed_col_length() const { | |
| 6569 | 219868 | const size_t max_length = pack_length(); | |
| 6570 |
2/2✓ Branch 0 taken 7610 times.
✓ Branch 1 taken 212260 times.
|
219870 | return (max_length > 255 ? 2 : 1) + max_length; |
| 6571 | } | ||
| 6572 | |||
| 6573 | 757778 | size_t Field_string::get_key_image(uchar *buff, size_t length, | |
| 6574 | imagetype) const { | ||
| 6575 | size_t bytes = | ||
| 6576 | 757778 | my_charpos(field_charset, (char *)ptr, (char *)ptr + field_length, | |
| 6577 | length / field_charset->mbmaxlen); | ||
| 6578 | 757778 | memcpy(buff, ptr, bytes); | |
| 6579 |
2/2✓ Branch 0 taken 448949 times.
✓ Branch 1 taken 308829 times.
|
757778 | if (bytes < length) |
| 6580 | 448949 | field_charset->cset->fill(field_charset, (char *)buff + bytes, | |
| 6581 | 448949 | length - bytes, field_charset->pad_char); | |
| 6582 | 757777 | return bytes; | |
| 6583 | } | ||
| 6584 | |||
| 6585 | /**************************************************************************** | ||
| 6586 | VARCHAR type | ||
| 6587 | Data in field->ptr is stored as: | ||
| 6588 | 1 or 2 bytes length-prefix-header (from Field_varstring::length_bytes) | ||
| 6589 | data | ||
| 6590 | |||
| 6591 | NOTE: | ||
| 6592 | When VARCHAR is stored in a key (for handler::index_read() etc) it's always | ||
| 6593 | stored with a 2 byte prefix. (Just like blob keys). | ||
| 6594 | |||
| 6595 | Normally length_bytes is calculated as (field_length < 256 : 1 ? 2) | ||
| 6596 | The exception is if there is a prefix key field that is part of a long | ||
| 6597 | VARCHAR, in which case field_length for this may be 1 but the length_bytes | ||
| 6598 | is 2. | ||
| 6599 | ****************************************************************************/ | ||
| 6600 | |||
| 6601 | /** | ||
| 6602 | Save the field metadata for varstring fields. | ||
| 6603 | |||
| 6604 | Saves the field length in the first byte. Note: may consume | ||
| 6605 | 2 bytes. Caller must ensure second byte is contiguous with | ||
| 6606 | first byte (e.g. array index 0,1). | ||
| 6607 | |||
| 6608 | @param metadata_ptr First byte of field metadata | ||
| 6609 | |||
| 6610 | @returns number of bytes written to metadata_ptr | ||
| 6611 | */ | ||
| 6612 | 6117380 | int Field_varstring::do_save_field_metadata(uchar *metadata_ptr) const { | |
| 6613 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6117380 times.
|
6117380 | assert(field_length <= 65535); |
| 6614 | 6117380 | int2store((char *)metadata_ptr, field_length); | |
| 6615 | 6117380 | return 2; | |
| 6616 | } | ||
| 6617 | |||
| 6618 | 576750132 | type_conversion_status Field_varstring::store(const char *from, size_t length, | |
| 6619 | const CHARSET_INFO *cs) { | ||
| 6620 |
4/6✓ Branch 0 taken 576750185 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 576674304 times.
✓ Branch 3 taken 75881 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 576674252 times.
|
576750132 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 6621 | size_t copy_length; | ||
| 6622 | const char *well_formed_error_pos; | ||
| 6623 | const char *cannot_convert_error_pos; | ||
| 6624 | const char *from_end_pos; | ||
| 6625 | |||
| 6626 | 1153500297 | copy_length = field_well_formed_copy_nchars( | |
| 6627 | 576750080 | field_charset, (char *)ptr + length_bytes, field_length, cs, from, length, | |
| 6628 |
1/2✓ Branch 0 taken 576750217 times.
✗ Branch 1 not taken.
|
576750080 | field_length / field_charset->mbmaxlen, &well_formed_error_pos, |
| 6629 | &cannot_convert_error_pos, &from_end_pos); | ||
| 6630 | |||
| 6631 |
2/2✓ Branch 0 taken 146917666 times.
✓ Branch 1 taken 429832551 times.
|
576750217 | if (length_bytes == 1) |
| 6632 | 146917666 | *ptr = (uchar)copy_length; | |
| 6633 | else | ||
| 6634 | 429832551 | int2store(ptr, static_cast<uint16>(copy_length)); | |
| 6635 | |||
| 6636 |
1/2✓ Branch 0 taken 576750192 times.
✗ Branch 1 not taken.
|
576750346 | return check_string_copy_error(well_formed_error_pos, |
| 6637 | cannot_convert_error_pos, from_end_pos, | ||
| 6638 | 1153500384 | from + length, true, cs); | |
| 6639 | } | ||
| 6640 | |||
| 6641 | 1543650 | type_conversion_status Field_varstring::store(longlong nr, bool unsigned_val) { | |
| 6642 | char buff[64]; | ||
| 6643 | uint length; | ||
| 6644 |
3/4✓ Branch 0 taken 133 times.
✓ Branch 1 taken 1543517 times.
✓ Branch 2 taken 1543650 times.
✗ Branch 3 not taken.
|
1543650 | length = (uint)(field_charset->cset->longlong10_to_str)( |
| 6645 | field_charset, buff, sizeof(buff), (unsigned_val ? 10 : -10), nr); | ||
| 6646 |
1/2✓ Branch 0 taken 1543650 times.
✗ Branch 1 not taken.
|
3087300 | return Field_varstring::store(buff, length, field_charset); |
| 6647 | } | ||
| 6648 | |||
| 6649 | 30136 | double Field_varstring::val_real() const { | |
| 6650 |
4/6✓ Branch 0 taken 30136 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30074 times.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 30074 times.
|
30136 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 6651 | int error; | ||
| 6652 | const char *end; | ||
| 6653 | double result; | ||
| 6654 |
1/2✓ Branch 0 taken 30136 times.
✗ Branch 1 not taken.
|
30136 | const CHARSET_INFO *cs = charset(); |
| 6655 | |||
| 6656 |
1/2✓ Branch 0 taken 30136 times.
✗ Branch 1 not taken.
|
30136 | uint length = data_length(); |
| 6657 |
1/2✓ Branch 0 taken 30136 times.
✗ Branch 1 not taken.
|
30136 | result = my_strntod(cs, (char *)ptr + length_bytes, length, &end, &error); |
| 6658 | |||
| 6659 |
4/6✓ Branch 0 taken 30136 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30136 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 966 times.
✓ Branch 5 taken 29170 times.
|
60272 | if ((error || (length != (uint)(end - (char *)ptr + length_bytes) && |
| 6660 |
2/2✓ Branch 0 taken 966 times.
✓ Branch 1 taken 29170 times.
|
30136 | !check_if_only_end_space( |
| 6661 |
1/2✓ Branch 0 taken 30136 times.
✗ Branch 1 not taken.
|
30136 | cs, end, (char *)ptr + length_bytes + length)))) { |
| 6662 |
2/4✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 966 times.
✗ Branch 3 not taken.
|
966 | push_numerical_conversion_warning(current_thd, (char *)ptr + length_bytes, |
| 6663 | length, cs, "DOUBLE", | ||
| 6664 | ER_TRUNCATED_WRONG_VALUE); | ||
| 6665 | } | ||
| 6666 | 30136 | return result; | |
| 6667 | } | ||
| 6668 | |||
| 6669 | 10 | longlong Field_varstring::val_int() const { | |
| 6670 |
3/6✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
|
10 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 6671 | int error; | ||
| 6672 | const char *end; | ||
| 6673 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | const CHARSET_INFO *cs = charset(); |
| 6674 | |||
| 6675 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | uint length = data_length(); |
| 6676 | longlong result = | ||
| 6677 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | my_strntoll(cs, (char *)ptr + length_bytes, length, 10, &end, &error); |
| 6678 | |||
| 6679 |
3/6✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
|
20 | if ((error || (length != (uint)(end - (char *)ptr + length_bytes) && |
| 6680 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | !check_if_only_end_space( |
| 6681 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | cs, end, (char *)ptr + length_bytes + length)))) { |
| 6682 | ✗ | push_numerical_conversion_warning(current_thd, (char *)ptr + length_bytes, | |
| 6683 | length, cs, "INTEGER", | ||
| 6684 | ER_TRUNCATED_WRONG_VALUE); | ||
| 6685 | } | ||
| 6686 | 10 | return result; | |
| 6687 | } | ||
| 6688 | |||
| 6689 | 802729247 | String *Field_varstring::val_str(String *, String *val_ptr) const { | |
| 6690 |
4/6✓ Branch 0 taken 802729778 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 802586468 times.
✓ Branch 3 taken 143310 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 802586466 times.
|
802729247 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 6691 | 710267635 | val_ptr->set(pointer_cast<const char *>(data_ptr()), data_length(), | |
| 6692 | 802729245 | field_charset); | |
| 6693 | 802728784 | return val_ptr; | |
| 6694 | } | ||
| 6695 | |||
| 6696 | 224 | my_decimal *Field_varstring::val_decimal(my_decimal *decimal_value) const { | |
| 6697 |
3/6✓ Branch 0 taken 224 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 224 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 224 times.
|
224 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 6698 | 224 | const CHARSET_INFO *cs = charset(); | |
| 6699 | 224 | uint length = data_length(); | |
| 6700 | 224 | int error = str2my_decimal(E_DEC_FATAL_ERROR, (char *)ptr + length_bytes, | |
| 6701 | length, cs, decimal_value); | ||
| 6702 | |||
| 6703 |
2/2✓ Branch 0 taken 39 times.
✓ Branch 1 taken 185 times.
|
224 | if (error) { |
| 6704 | 39 | push_numerical_conversion_warning(current_thd, (char *)ptr + length_bytes, | |
| 6705 | length, cs, "DECIMAL", | ||
| 6706 | ER_TRUNCATED_WRONG_VALUE); | ||
| 6707 | } | ||
| 6708 | 224 | return decimal_value; | |
| 6709 | } | ||
| 6710 | |||
| 6711 | 232222 | int Field_varstring::cmp_max(const uchar *a_ptr, const uchar *b_ptr, | |
| 6712 | uint max_len) const { | ||
| 6713 | uint a_length, b_length; | ||
| 6714 | int diff; | ||
| 6715 | |||
| 6716 |
2/2✓ Branch 0 taken 82350 times.
✓ Branch 1 taken 149872 times.
|
232222 | if (length_bytes == 1) { |
| 6717 | 82350 | a_length = (uint)*a_ptr; | |
| 6718 | 82350 | b_length = (uint)*b_ptr; | |
| 6719 | } else { | ||
| 6720 | 149872 | a_length = uint2korr(a_ptr); | |
| 6721 | 149872 | b_length = uint2korr(b_ptr); | |
| 6722 | } | ||
| 6723 | 232222 | a_length = std::min(a_length, max_len); | |
| 6724 | 232222 | b_length = std::min(b_length, max_len); | |
| 6725 | 464444 | diff = field_charset->coll->strnncollsp(field_charset, a_ptr + length_bytes, | |
| 6726 |
1/2✓ Branch 0 taken 232222 times.
✗ Branch 1 not taken.
|
232222 | a_length, b_ptr + length_bytes, |
| 6727 | b_length); | ||
| 6728 | 232222 | return diff; | |
| 6729 | } | ||
| 6730 | |||
| 6731 | /** | ||
| 6732 | @note | ||
| 6733 | varstring and blob keys are ALWAYS stored with a 2 byte length prefix | ||
| 6734 | */ | ||
| 6735 | |||
| 6736 | 72533 | int Field_varstring::key_cmp(const uchar *key_ptr, uint max_key_length) const { | |
| 6737 |
1/2✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
|
72533 | uint length = data_length(); |
| 6738 | 72533 | uint local_char_length = max_key_length / field_charset->mbmaxlen; | |
| 6739 | |||
| 6740 | 72533 | local_char_length = | |
| 6741 |
1/2✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
|
72533 | my_charpos(field_charset, ptr + length_bytes, ptr + length_bytes + length, |
| 6742 | local_char_length); | ||
| 6743 | 72533 | length = std::min(length, local_char_length); | |
| 6744 |
1/2✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
|
72533 | return field_charset->coll->strnncollsp(field_charset, ptr + length_bytes, |
| 6745 | length, key_ptr + HA_KEY_BLOB_LENGTH, | ||
| 6746 | 217599 | uint2korr(key_ptr)); | |
| 6747 | } | ||
| 6748 | |||
| 6749 | /** | ||
| 6750 | Compare to key segments (always 2 byte length prefix). | ||
| 6751 | |||
| 6752 | @note | ||
| 6753 | This is used only to compare key segments created for index_read(). | ||
| 6754 | (keys are created and compared in key.cc) | ||
| 6755 | */ | ||
| 6756 | |||
| 6757 | 295977 | int Field_varstring::key_cmp(const uchar *a, const uchar *b) const { | |
| 6758 | 295977 | return field_charset->coll->strnncollsp(field_charset, a + HA_KEY_BLOB_LENGTH, | |
| 6759 | 295977 | uint2korr(a), b + HA_KEY_BLOB_LENGTH, | |
| 6760 | 591954 | uint2korr(b)); | |
| 6761 | } | ||
| 6762 | |||
| 6763 | 660871 | size_t Field_varstring::make_sort_key(uchar *to, size_t length) const { | |
| 6764 | 660871 | const int flags = | |
| 6765 |
2/2✓ Branch 0 taken 482256 times.
✓ Branch 1 taken 178615 times.
|
660871 | (field_charset->pad_attribute == NO_PAD) ? 0 : MY_STRXFRM_PAD_TO_MAXLEN; |
| 6766 | |||
| 6767 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 660871 times.
|
660871 | assert(char_length_cache == char_length()); |
| 6768 | 1982613 | return field_charset->coll->strnxfrm(field_charset, to, length, | |
| 6769 | 660871 | char_length_cache, ptr + length_bytes, | |
| 6770 | 660871 | data_length(), flags); | |
| 6771 | } | ||
| 6772 | |||
| 6773 | 4288574 | enum ha_base_keytype Field_varstring::key_type() const { | |
| 6774 | enum ha_base_keytype res; | ||
| 6775 | |||
| 6776 |
2/2✓ Branch 0 taken 359158 times.
✓ Branch 1 taken 3929416 times.
|
4288574 | if (binary()) |
| 6777 |
2/2✓ Branch 0 taken 355912 times.
✓ Branch 1 taken 3246 times.
|
359158 | res = length_bytes == 1 ? HA_KEYTYPE_VARBINARY1 : HA_KEYTYPE_VARBINARY2; |
| 6778 | else | ||
| 6779 |
2/2✓ Branch 0 taken 2318406 times.
✓ Branch 1 taken 1611010 times.
|
3929416 | res = length_bytes == 1 ? HA_KEYTYPE_VARTEXT1 : HA_KEYTYPE_VARTEXT2; |
| 6780 | 4288574 | return res; | |
| 6781 | } | ||
| 6782 | |||
| 6783 | 2358435 | void Field_varstring::sql_type(String &res) const { | |
| 6784 | 2358435 | const CHARSET_INFO *cs = res.charset(); | |
| 6785 | size_t length; | ||
| 6786 | |||
| 6787 | 2358440 | length = cs->cset->snprintf(cs, res.ptr(), res.alloced_length(), "%s(%d)", | |
| 6788 |
2/2✓ Branch 0 taken 2323669 times.
✓ Branch 1 taken 34771 times.
|
2358440 | (has_charset() ? "varchar" : "varbinary"), |
| 6789 | 2358437 | (int)field_length / charset()->mbmaxlen); | |
| 6790 | 2358442 | res.length(length); | |
| 6791 | 2358442 | } | |
| 6792 | |||
| 6793 | 932787241 | uint32 Field_varstring::data_length(ptrdiff_t row_offset) const { | |
| 6794 |
2/2✓ Branch 0 taken 456679066 times.
✓ Branch 1 taken 476108175 times.
|
1408896499 | return length_bytes == 1 ? (uint32) * (ptr + row_offset) |
| 6795 | 1408896499 | : uint2korr(ptr + row_offset); | |
| 6796 | } | ||
| 6797 | |||
| 6798 | /* | ||
| 6799 | Functions to create a packed row. | ||
| 6800 | Here the number of length bytes are depending on the given max_length | ||
| 6801 | */ | ||
| 6802 | |||
| 6803 | 86076331 | uchar *Field_varstring::pack(uchar *to, const uchar *from, | |
| 6804 | size_t max_length) const { | ||
| 6805 |
2/2✓ Branch 0 taken 12098646 times.
✓ Branch 1 taken 73977685 times.
|
86076331 | uint length = length_bytes == 1 ? (uint)*from : uint2korr(from); |
| 6806 |
2/2✓ Branch 0 taken 3523 times.
✓ Branch 1 taken 86072808 times.
|
86076331 | if (max_length < length_bytes) |
| 6807 | 3523 | length = 0; | |
| 6808 |
2/2✓ Branch 0 taken 30993 times.
✓ Branch 1 taken 86041815 times.
|
86072808 | else if (length > max_length - length_bytes) |
| 6809 | 30993 | length = max_length - length_bytes; | |
| 6810 | |||
| 6811 | /* Length always stored little-endian */ | ||
| 6812 |
2/2✓ Branch 0 taken 86076272 times.
✓ Branch 1 taken 59 times.
|
86076331 | if (max_length >= 1) { |
| 6813 | 86076272 | *to++ = length & 0xFF; | |
| 6814 |
4/4✓ Branch 0 taken 73977631 times.
✓ Branch 1 taken 12098641 times.
✓ Branch 2 taken 73974167 times.
✓ Branch 3 taken 3464 times.
|
86076272 | if (length_bytes == 2 && max_length >= 2) *to++ = (length >> 8) & 0xFF; |
| 6815 | } | ||
| 6816 | |||
| 6817 | /* Store bytes of string */ | ||
| 6818 | 86076331 | memcpy(to, from + length_bytes, length); | |
| 6819 | 86076331 | return to + length; | |
| 6820 | } | ||
| 6821 | |||
| 6822 | /** | ||
| 6823 | Unpack a varstring field from row data. | ||
| 6824 | |||
| 6825 | This method is used to unpack a varstring field from a master | ||
| 6826 | whose size of the field is less than that of the slave. | ||
| 6827 | |||
| 6828 | @note | ||
| 6829 | The string length is always packed little-endian. | ||
| 6830 | |||
| 6831 | @param to Destination of the data | ||
| 6832 | @param from Source of the data | ||
| 6833 | @param param_data Length bytes from the master's field data | ||
| 6834 | |||
| 6835 | @return New pointer into memory based on from + length of the data | ||
| 6836 | */ | ||
| 6837 | 115572968 | const uchar *Field_varstring::unpack(uchar *to, const uchar *from, | |
| 6838 | uint param_data) { | ||
| 6839 | uint length; | ||
| 6840 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 78159 times.
|
78163 | uint l_bytes = (param_data && (param_data < field_length)) |
| 6841 |
4/4✓ Branch 0 taken 78163 times.
✓ Branch 1 taken 115494805 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
|
115651131 | ? (param_data <= 255) ? 1 : 2 |
| 6842 | : length_bytes; | ||
| 6843 |
2/2✓ Branch 0 taken 52302496 times.
✓ Branch 1 taken 63270472 times.
|
115572968 | if (l_bytes == 1) { |
| 6844 | 52302496 | to[0] = *from++; | |
| 6845 | 52302496 | length = to[0]; | |
| 6846 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 52302495 times.
|
52302496 | if (length_bytes == 2) to[1] = 0; |
| 6847 | } else /* l_bytes == 2 */ | ||
| 6848 | { | ||
| 6849 | 63270472 | length = uint2korr(from); | |
| 6850 | 63270474 | to[0] = *from++; | |
| 6851 | 63270474 | to[1] = *from++; | |
| 6852 | } | ||
| 6853 |
2/2✓ Branch 0 taken 113833822 times.
✓ Branch 1 taken 1739148 times.
|
115572970 | if (length) memcpy(to + length_bytes, from, length); |
| 6854 | 115572970 | return from + length; | |
| 6855 | } | ||
| 6856 | |||
| 6857 | 48628699 | size_t Field_varstring::get_key_image(uchar *buff, size_t length, | |
| 6858 | imagetype) const { | ||
| 6859 | /* | ||
| 6860 | If NULL, data bytes may have been left random by the storage engine, so | ||
| 6861 | don't try to read them. | ||
| 6862 | */ | ||
| 6863 |
4/6✓ Branch 0 taken 48628741 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 48628734 times.
✓ Branch 4 taken 48628717 times.
✗ Branch 5 not taken.
|
48628699 | uint f_length = is_null() ? 0 : data_length(); |
| 6864 | 48628724 | uint local_char_length = length / field_charset->mbmaxlen; | |
| 6865 | 48628724 | uchar *pos = ptr + length_bytes; | |
| 6866 | 48628855 | local_char_length = | |
| 6867 |
1/2✓ Branch 0 taken 48628855 times.
✗ Branch 1 not taken.
|
48628724 | my_charpos(field_charset, pos, pos + f_length, local_char_length); |
| 6868 | 48628855 | f_length = std::min(f_length, local_char_length); | |
| 6869 | /* Key is always stored with 2 bytes */ | ||
| 6870 | 48628852 | int2store(buff, f_length); | |
| 6871 | 48628772 | memcpy(buff + HA_KEY_BLOB_LENGTH, pos, f_length); | |
| 6872 |
2/2✓ Branch 0 taken 48628280 times.
✓ Branch 1 taken 492 times.
|
48628772 | if (f_length < length) { |
| 6873 | /* | ||
| 6874 | Must clear this as we do a memcmp in opt_range.cc to detect | ||
| 6875 | identical keys | ||
| 6876 | */ | ||
| 6877 | 48628280 | memset(buff + HA_KEY_BLOB_LENGTH + f_length, 0, (length - f_length)); | |
| 6878 | } | ||
| 6879 | 48628772 | return HA_KEY_BLOB_LENGTH + f_length; | |
| 6880 | } | ||
| 6881 | |||
| 6882 | 5948 | void Field_varstring::set_key_image(const uchar *buff, size_t length) { | |
| 6883 | 5948 | length = uint2korr(buff); // Real length is here | |
| 6884 | 5948 | (void)Field_varstring::store((const char *)buff + HA_KEY_BLOB_LENGTH, length, | |
| 6885 | field_charset); | ||
| 6886 | 5948 | } | |
| 6887 | |||
| 6888 | 674780 | int Field_varstring::cmp_binary(const uchar *a_ptr, const uchar *b_ptr, | |
| 6889 | uint32 max_length) const { | ||
| 6890 | uint32 a_length, b_length; | ||
| 6891 | |||
| 6892 |
2/2✓ Branch 0 taken 647929 times.
✓ Branch 1 taken 26851 times.
|
674780 | if (length_bytes == 1) { |
| 6893 | 647929 | a_length = (uint)*a_ptr; | |
| 6894 | 647929 | b_length = (uint)*b_ptr; | |
| 6895 | } else { | ||
| 6896 | 26851 | a_length = uint2korr(a_ptr); | |
| 6897 | 26851 | b_length = uint2korr(b_ptr); | |
| 6898 | } | ||
| 6899 | 674780 | a_length = std::min(a_length, max_length); | |
| 6900 | 674780 | b_length = std::min(b_length, max_length); | |
| 6901 |
2/2✓ Branch 0 taken 212329 times.
✓ Branch 1 taken 462451 times.
|
674780 | if (a_length != b_length) return 1; |
| 6902 | 462451 | return memcmp(a_ptr + length_bytes, b_ptr + length_bytes, a_length); | |
| 6903 | } | ||
| 6904 | |||
| 6905 | 2343680 | Field *Field_varstring::new_field(MEM_ROOT *root, TABLE *new_table) const { | |
| 6906 | Field_varstring *res = | ||
| 6907 | 2343680 | down_cast<Field_varstring *>(Field::new_field(root, new_table)); | |
| 6908 |
2/2✓ Branch 0 taken 2343680 times.
✓ Branch 1 taken 2 times.
|
2343682 | if (res) res->length_bytes = length_bytes; |
| 6909 | 2343682 | return res; | |
| 6910 | } | ||
| 6911 | |||
| 6912 | 628688 | Field *Field_varstring::new_key_field(MEM_ROOT *root, TABLE *new_table, | |
| 6913 | uchar *new_ptr, uchar *new_null_ptr, | ||
| 6914 | uint new_null_bit) const { | ||
| 6915 | Field_varstring *res; | ||
| 6916 |
1/2✓ Branch 0 taken 628706 times.
✗ Branch 1 not taken.
|
628688 | if ((res = (Field_varstring *)Field::new_key_field( |
| 6917 | root, new_table, new_ptr, new_null_ptr, new_null_bit))) { | ||
| 6918 | /* Keys length prefixes are always packed with 2 bytes */ | ||
| 6919 | 628706 | res->length_bytes = 2; | |
| 6920 | } | ||
| 6921 | 628705 | return res; | |
| 6922 | } | ||
| 6923 | |||
| 6924 | 31102 | uint Field_varstring::is_equal(const Create_field *new_field) const { | |
| 6925 |
1/2✓ Branch 0 taken 31102 times.
✗ Branch 1 not taken.
|
31102 | DBUG_TRACE; |
| 6926 |
3/4✓ Branch 0 taken 31102 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 284 times.
✓ Branch 3 taken 30818 times.
|
31102 | if (change_prevents_inplace(*this, *new_field)) { |
| 6927 | 284 | return IS_EQUAL_NO; | |
| 6928 | } | ||
| 6929 | |||
| 6930 |
4/4✓ Branch 0 taken 30724 times.
✓ Branch 1 taken 94 times.
✓ Branch 2 taken 30598 times.
✓ Branch 3 taken 220 times.
|
61542 | if (new_field->charset == field_charset && |
| 6931 |
3/4✓ Branch 0 taken 30724 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30598 times.
✓ Branch 3 taken 126 times.
|
30724 | new_field->pack_length() == pack_length()) { |
| 6932 | 30598 | return IS_EQUAL_YES; | |
| 6933 | } | ||
| 6934 | |||
| 6935 | 220 | return IS_EQUAL_PACK_LENGTH; | |
| 6936 | 31102 | } | |
| 6937 | |||
| 6938 | 1394 | void Field_varstring::hash(ulong *nr, ulong *nr2) const { | |
| 6939 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 1379 times.
|
1394 | if (is_null()) { |
| 6940 | 15 | *nr ^= (*nr << 1) | 1; | |
| 6941 | } else { | ||
| 6942 |
1/2✓ Branch 0 taken 1379 times.
✗ Branch 1 not taken.
|
1379 | uint len = data_length(); |
| 6943 |
1/2✓ Branch 0 taken 1379 times.
✗ Branch 1 not taken.
|
1379 | const CHARSET_INFO *cs = charset(); |
| 6944 | 1379 | uint64 tmp1 = *nr; | |
| 6945 | 1379 | uint64 tmp2 = *nr2; | |
| 6946 |
1/2✓ Branch 0 taken 1379 times.
✗ Branch 1 not taken.
|
1379 | cs->coll->hash_sort(cs, ptr + length_bytes, len, &tmp1, &tmp2); |
| 6947 | |||
| 6948 | // NOTE: This truncates to 32-bit on Windows, to keep on-disk stability. | ||
| 6949 | 1379 | *nr = static_cast<ulong>(tmp1); | |
| 6950 | 1379 | *nr2 = static_cast<ulong>(tmp2); | |
| 6951 | } | ||
| 6952 | 1394 | } | |
| 6953 | |||
| 6954 | /**************************************************************************** | ||
| 6955 | ** blob type | ||
| 6956 | ** A blob is saved as a length and a pointer. The length is stored in the | ||
| 6957 | ** packlength slot and may be from 1-4. | ||
| 6958 | ****************************************************************************/ | ||
| 6959 | |||
| 6960 | ✗ | Field_blob::Field_blob(uint32 packlength_arg) | |
| 6961 | : Field_longstr(nullptr, 0, &dummy_null_buffer, 0, NONE, "temp", | ||
| 6962 | system_charset_info), | ||
| 6963 | ✗ | packlength(packlength_arg), | |
| 6964 | ✗ | m_keep_old_value(false) {} | |
| 6965 | |||
| 6966 | 6683690 | Field_blob::Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, | |
| 6967 | uchar auto_flags_arg, const char *field_name_arg, | ||
| 6968 | TABLE_SHARE *share, uint blob_pack_length, | ||
| 6969 | 6683690 | const CHARSET_INFO *cs) | |
| 6970 | 20051069 | : Field_longstr(ptr_arg, BLOB_PACK_LENGTH_TO_MAX_LENGH(blob_pack_length), | |
| 6971 | null_ptr_arg, null_bit_arg, auto_flags_arg, field_name_arg, | ||
| 6972 | cs), | ||
| 6973 | 6683689 | packlength(blob_pack_length), | |
| 6974 |
1/2✓ Branch 0 taken 6683689 times.
✗ Branch 1 not taken.
|
6683690 | m_keep_old_value(false) { |
| 6975 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6683690 times.
|
6683690 | assert(blob_pack_length <= 4); // Only pack lengths 1-4 supported currently |
| 6976 | 6683690 | set_flag(BLOB_FLAG); | |
| 6977 | 6683690 | share->blob_fields++; | |
| 6978 | /* TODO: why do not fill table->s->blob_field array here? */ | ||
| 6979 | 6683690 | } | |
| 6980 | |||
| 6981 | 92665384 | void store_blob_length(uchar *i_ptr, uint i_packlength, uint32 i_number) { | |
| 6982 |
4/5✓ Branch 0 taken 2255781 times.
✓ Branch 1 taken 30973688 times.
✓ Branch 2 taken 26429123 times.
✓ Branch 3 taken 33007006 times.
✗ Branch 4 not taken.
|
92665384 | switch (i_packlength) { |
| 6983 | 2255781 | case 1: | |
| 6984 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2255781 times.
|
2255781 | assert(i_number <= 0xff); |
| 6985 | 2255781 | i_ptr[0] = static_cast<uchar>(i_number); | |
| 6986 | 2255781 | break; | |
| 6987 | 30973688 | case 2: | |
| 6988 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30973688 times.
|
30973688 | assert(i_number <= 0xffff); |
| 6989 | 30973688 | int2store(i_ptr, static_cast<unsigned short>(i_number)); | |
| 6990 | 30973610 | break; | |
| 6991 | 26429123 | case 3: | |
| 6992 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26429123 times.
|
26429123 | assert(i_number <= 0xffffff); |
| 6993 | 26429123 | int3store(i_ptr, i_number); | |
| 6994 | 26429120 | break; | |
| 6995 | 33007006 | case 4: | |
| 6996 | 33007006 | int4store(i_ptr, i_number); | |
| 6997 | } | ||
| 6998 | 92665325 | } | |
| 6999 | |||
| 7000 | 290565237 | uint32 Field_blob::get_length(const uchar *pos, uint packlength_arg) { | |
| 7001 |
4/5✓ Branch 0 taken 4366432 times.
✓ Branch 1 taken 115991682 times.
✓ Branch 2 taken 125344574 times.
✓ Branch 3 taken 44862660 times.
✗ Branch 4 not taken.
|
290565237 | switch (packlength_arg) { |
| 7002 | 4366432 | case 1: | |
| 7003 | 4366432 | return (uint32)pos[0]; | |
| 7004 | 115991682 | case 2: | |
| 7005 | 115991682 | return uint2korr(pos); | |
| 7006 | 125344574 | case 3: | |
| 7007 | 125344574 | return uint3korr(pos); | |
| 7008 | 44862660 | case 4: | |
| 7009 | 44862660 | return uint4korr(pos); | |
| 7010 | } | ||
| 7011 | /* When expanding this, see also MAX_FIELD_BLOBLENGTH. */ | ||
| 7012 | ✗ | return 0; // Impossible | |
| 7013 | } | ||
| 7014 | |||
| 7015 | /** | ||
| 7016 | Store a blob value to memory storage. | ||
| 7017 | @param from the string value to store. | ||
| 7018 | @param length length of the string value. | ||
| 7019 | @param cs character set of the string value. | ||
| 7020 | @param max_length Cut at this length safely (multibyte aware). | ||
| 7021 | */ | ||
| 7022 | 4737 | type_conversion_status Field_blob::store_to_mem(const char *from, size_t length, | |
| 7023 | const CHARSET_INFO *cs, | ||
| 7024 | size_t max_length, | ||
| 7025 | Blob_mem_storage *) { | ||
| 7026 | /* | ||
| 7027 | We don't need to support escaping or character set conversions here, | ||
| 7028 | because store_to_mem() is currently called only when we process | ||
| 7029 | queries having GROUP_CONCAT with ORDER BY or DISTINCT, | ||
| 7030 | hence some assersions: | ||
| 7031 | */ | ||
| 7032 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4737 times.
|
4737 | assert(field_charset == cs); |
| 7033 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4737 times.
|
4737 | assert(length <= max_data_length()); |
| 7034 | |||
| 7035 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4729 times.
|
4737 | if (length > max_length) { |
| 7036 | int well_formed_error; | ||
| 7037 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | length = cs->cset->well_formed_len(cs, from, from + max_length, length, |
| 7038 | &well_formed_error); | ||
| 7039 | 8 | table->blob_storage->set_truncated_value(true); | |
| 7040 | } | ||
| 7041 | char *tmp; | ||
| 7042 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4737 times.
|
4737 | if (!(tmp = table->blob_storage->store(from, length))) { |
| 7043 | ✗ | reset(); | |
| 7044 | ✗ | return TYPE_ERR_OOM; | |
| 7045 | } | ||
| 7046 | 4737 | store_ptr_and_length(tmp, length); | |
| 7047 | 4737 | return TYPE_OK; | |
| 7048 | } | ||
| 7049 | |||
| 7050 | 82111218 | type_conversion_status Field_blob::store_internal(const char *from, | |
| 7051 | size_t length, | ||
| 7052 | const CHARSET_INFO *cs) { | ||
| 7053 | size_t new_length; | ||
| 7054 | char buff[STRING_BUFFER_USUAL_SIZE], *tmp; | ||
| 7055 | 82111218 | String tmpstr(buff, sizeof(buff), &my_charset_bin); | |
| 7056 | |||
| 7057 |
1/2✓ Branch 0 taken 82111347 times.
✗ Branch 1 not taken.
|
82111269 | THD *thd = current_thd; |
| 7058 | |||
| 7059 | /* | ||
| 7060 | If the 'from' address is in the range of the temporary 'value'- | ||
| 7061 | object we need to copy the content to a different location or it will be | ||
| 7062 | invalidated when the 'value'-object is reallocated to make room for | ||
| 7063 | the new character set. | ||
| 7064 | */ | ||
| 7065 | 82111347 | size_t max_len = max_data_length(); | |
| 7066 |
6/6✓ Branch 0 taken 53281205 times.
✓ Branch 1 taken 28830141 times.
✓ Branch 2 taken 16043184 times.
✓ Branch 3 taken 37237864 times.
✓ Branch 4 taken 16043181 times.
✓ Branch 5 taken 66068008 times.
|
82111129 | if (from >= value.ptr() && from <= value.ptr() + value.length()) { |
| 7067 | /* | ||
| 7068 | If content of the 'from'-address is cached in the 'value'-object | ||
| 7069 | it is possible that the content needs a character conversion. | ||
| 7070 | */ | ||
| 7071 |
3/4✓ Branch 0 taken 16043132 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16035466 times.
✓ Branch 3 taken 7666 times.
|
16043181 | if (!String::needs_conversion_on_storage(length, cs, field_charset)) { |
| 7072 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 16035463 times.
|
16035466 | if (length > max_len) { |
| 7073 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | store_ptr_and_length(from, max_len); |
| 7074 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (thd->check_for_truncated_fields) { |
| 7075 |
6/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
|
3 | if (thd->is_strict_mode() && !thd->lex->is_ignore()) |
| 7076 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | set_warning(Sql_condition::SL_WARNING, ER_DATA_TOO_LONG, 1); |
| 7077 | else | ||
| 7078 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); |
| 7079 | } | ||
| 7080 | 3 | return TYPE_WARN_TRUNCATED; | |
| 7081 | } | ||
| 7082 |
1/2✓ Branch 0 taken 16035410 times.
✗ Branch 1 not taken.
|
16035463 | store_ptr_and_length(from, length); |
| 7083 | 16035410 | return TYPE_OK; | |
| 7084 | } | ||
| 7085 |
2/4✓ Branch 0 taken 7685 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7685 times.
|
7685 | if (tmpstr.copy(from, length, cs)) goto oom_error; |
| 7086 | 7685 | from = tmpstr.ptr(); | |
| 7087 | } | ||
| 7088 | |||
| 7089 | 66075693 | new_length = min<size_t>(max_len, field_charset->mbmaxlen * length); | |
| 7090 | |||
| 7091 |
2/4✓ Branch 0 taken 66075507 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 66075507 times.
|
66075460 | if (value.alloc(new_length)) goto oom_error; |
| 7092 | |||
| 7093 | 66075507 | tmp = value.ptr(); | |
| 7094 | |||
| 7095 | { | ||
| 7096 | const char *well_formed_error_pos; | ||
| 7097 | const char *cannot_convert_error_pos; | ||
| 7098 | const char *from_end_pos; | ||
| 7099 | /* | ||
| 7100 | "length" is OK as "nchars" argument to well_formed_copy_nchars as this | ||
| 7101 | is never used to limit the length of the data. The cut of long data | ||
| 7102 | is done with the new_length value. | ||
| 7103 | */ | ||
| 7104 |
1/2✓ Branch 0 taken 66075539 times.
✗ Branch 1 not taken.
|
66075561 | size_t copy_length = field_well_formed_copy_nchars( |
| 7105 | field_charset, tmp, new_length, cs, from, length, length, | ||
| 7106 | &well_formed_error_pos, &cannot_convert_error_pos, &from_end_pos); | ||
| 7107 | |||
| 7108 |
1/2✓ Branch 0 taken 66075795 times.
✗ Branch 1 not taken.
|
66075539 | store_ptr_and_length(tmp, copy_length); |
| 7109 |
1/2✓ Branch 0 taken 66075733 times.
✗ Branch 1 not taken.
|
66075795 | return check_string_copy_error(well_formed_error_pos, |
| 7110 | cannot_convert_error_pos, from_end_pos, | ||
| 7111 | 66075733 | from + length, true, cs); | |
| 7112 | } | ||
| 7113 | |||
| 7114 | ✗ | oom_error: | |
| 7115 | /* Fatal OOM error */ | ||
| 7116 | ✗ | reset(); | |
| 7117 | ✗ | return TYPE_ERR_OOM; | |
| 7118 | 82111146 | } | |
| 7119 | |||
| 7120 | 84614705 | type_conversion_status Field_blob::store(const char *from, size_t length, | |
| 7121 | const CHARSET_INFO *cs) { | ||
| 7122 |
4/6✓ Branch 0 taken 84614843 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84598359 times.
✓ Branch 3 taken 16484 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 84598975 times.
|
84614705 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 7123 | |||
| 7124 |
2/2✓ Branch 0 taken 4737 times.
✓ Branch 1 taken 84610584 times.
|
84615321 | if (table->blob_storage) // GROUP_CONCAT with ORDER BY | DISTINCT |
| 7125 | 14211 | return store_to_mem(from, length, cs, | |
| 7126 | 4737 | current_thd->variables.group_concat_max_len, | |
| 7127 | 9474 | table->blob_storage); | |
| 7128 | |||
| 7129 | 84610584 | return store_internal(from, length, cs); | |
| 7130 | } | ||
| 7131 | |||
| 7132 | 397 | type_conversion_status Field_blob::store(double nr) { | |
| 7133 | 397 | const CHARSET_INFO *cs = charset(); | |
| 7134 | 397 | value.set_real(nr, DECIMAL_NOT_SPECIFIED, cs); | |
| 7135 | 397 | return Field_blob::store(value.ptr(), value.length(), cs); | |
| 7136 | } | ||
| 7137 | |||
| 7138 | 605500 | type_conversion_status Field_blob::store(longlong nr, bool unsigned_val) { | |
| 7139 | 605500 | const CHARSET_INFO *cs = charset(); | |
| 7140 | 605500 | value.set_int(nr, unsigned_val, cs); | |
| 7141 | 605500 | return Field_blob::store(value.ptr(), value.length(), cs); | |
| 7142 | } | ||
| 7143 | |||
| 7144 | 15252972 | type_conversion_status Field_blob::store(const Field *from) { | |
| 7145 | 15252972 | from->val_str(&value); | |
| 7146 | |||
| 7147 | /* | ||
| 7148 | Copy value if copy_blobs is set, or source is part of the table's | ||
| 7149 | writeset. | ||
| 7150 | */ | ||
| 7151 |
8/8✓ Branch 0 taken 9975 times.
✓ Branch 1 taken 15242997 times.
✓ Branch 2 taken 9622 times.
✓ Branch 3 taken 353 times.
✓ Branch 4 taken 5265 times.
✓ Branch 5 taken 4357 times.
✓ Branch 6 taken 15248262 times.
✓ Branch 7 taken 4710 times.
|
15252972 | if (table->copy_blobs || (!value.is_alloced() && from->is_updatable())) |
| 7152 | 15248262 | value.copy(); | |
| 7153 | |||
| 7154 | 15252972 | return store(value.ptr(), value.length(), from->charset()); | |
| 7155 | } | ||
| 7156 | |||
| 7157 | 1111 | double Field_blob::val_real() const { | |
| 7158 |
3/6✓ Branch 0 taken 1111 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1111 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1111 times.
|
1111 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 7159 | |||
| 7160 |
1/2✓ Branch 0 taken 1111 times.
✗ Branch 1 not taken.
|
1111 | const char *blob = pointer_cast<const char *>(get_blob_data()); |
| 7161 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1111 times.
|
1111 | if (blob == nullptr) return 0.0; |
| 7162 | |||
| 7163 | int not_used; | ||
| 7164 | const char *end_not_used; | ||
| 7165 |
4/8✓ Branch 0 taken 1111 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1111 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1111 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1111 times.
✗ Branch 7 not taken.
|
1111 | return my_strntod(charset(), blob, get_length(ptr), &end_not_used, ¬_used); |
| 7166 | } | ||
| 7167 | |||
| 7168 | 13 | longlong Field_blob::val_int() const { | |
| 7169 |
3/6✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 13 times.
|
13 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 7170 | |||
| 7171 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | const char *blob = pointer_cast<const char *>(get_blob_data()); |
| 7172 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (blob == nullptr) return 0; |
| 7173 | |||
| 7174 | int not_used; | ||
| 7175 |
4/8✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13 times.
✗ Branch 7 not taken.
|
13 | return my_strntoll(charset(), blob, get_length(ptr), 10, nullptr, ¬_used); |
| 7176 | } | ||
| 7177 | |||
| 7178 | 264771192 | String *Field_blob::val_str(String *, String *val_ptr) const { | |
| 7179 |
4/6✓ Branch 0 taken 264771229 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 264754642 times.
✓ Branch 3 taken 16587 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 264754733 times.
|
264771192 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 7180 | |||
| 7181 | 264771283 | const char *blob = pointer_cast<const char *>(get_blob_data()); | |
| 7182 |
2/2✓ Branch 0 taken 1424921 times.
✓ Branch 1 taken 263346408 times.
|
264771329 | if (blob == nullptr) |
| 7183 | 1424921 | val_ptr->set("", 0, charset()); // A bit safer than ->length(0) | |
| 7184 | else | ||
| 7185 | 263346408 | val_ptr->set(blob, get_length(ptr), charset()); | |
| 7186 | 264771426 | return val_ptr; | |
| 7187 | } | ||
| 7188 | |||
| 7189 | 13 | my_decimal *Field_blob::val_decimal(my_decimal *decimal_value) const { | |
| 7190 |
3/6✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 13 times.
|
13 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 7191 | size_t length; | ||
| 7192 | 13 | const char *blob = pointer_cast<const char *>(get_blob_data()); | |
| 7193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (!blob) { |
| 7194 | ✗ | blob = ""; | |
| 7195 | ✗ | length = 0; | |
| 7196 | } else | ||
| 7197 | 13 | length = get_length(ptr); | |
| 7198 | |||
| 7199 | 13 | str2my_decimal(E_DEC_FATAL_ERROR, blob, length, charset(), decimal_value); | |
| 7200 | 13 | return decimal_value; | |
| 7201 | } | ||
| 7202 | |||
| 7203 | 932861 | int Field_blob::cmp(const uchar *a, uint32 a_length, const uchar *b, | |
| 7204 | uint32 b_length) const { | ||
| 7205 | 932861 | return field_charset->coll->strnncollsp(field_charset, a, a_length, b, | |
| 7206 | 932861 | b_length); | |
| 7207 | } | ||
| 7208 | |||
| 7209 | 901371 | int Field_blob::cmp_max(const uchar *a_ptr, const uchar *b_ptr, | |
| 7210 | uint max_length) const { | ||
| 7211 | 901371 | const uchar *blob1 = get_blob_data(a_ptr + packlength); | |
| 7212 | 901371 | const uchar *blob2 = get_blob_data(b_ptr + packlength); | |
| 7213 | 901371 | uint32 a_len = min(get_length(a_ptr), max_length); | |
| 7214 | 901371 | uint32 b_len = min(get_length(b_ptr), max_length); | |
| 7215 | 901371 | return Field_blob::cmp(blob1, a_len, blob2, b_len); | |
| 7216 | } | ||
| 7217 | |||
| 7218 | 164826 | int Field_blob::cmp_binary(const uchar *a_ptr, const uchar *b_ptr, | |
| 7219 | uint32 max_length) const { | ||
| 7220 | 164826 | const uchar *a = get_blob_data(a_ptr + packlength); | |
| 7221 | 164826 | const uchar *b = get_blob_data(b_ptr + packlength); | |
| 7222 |
1/2✓ Branch 0 taken 164826 times.
✗ Branch 1 not taken.
|
164826 | uint32 a_length = min(get_length(a_ptr), max_length); |
| 7223 |
1/2✓ Branch 0 taken 164827 times.
✗ Branch 1 not taken.
|
164826 | uint32 b_length = min(get_length(b_ptr), max_length); |
| 7224 | 164827 | const uint32 min_a_b = min(a_length, b_length); | |
| 7225 |
2/2✓ Branch 0 taken 114376 times.
✓ Branch 1 taken 50451 times.
|
164827 | uint diff = min_a_b == 0 ? 0 : memcmp(a, b, min_a_b); // memcmp(a, b, 0) == 0 |
| 7226 |
2/2✓ Branch 0 taken 105343 times.
✓ Branch 1 taken 59484 times.
|
164827 | return diff ? diff : (int)(a_length - b_length); |
| 7227 | } | ||
| 7228 | |||
| 7229 | /* The following is used only when comparing a key */ | ||
| 7230 | |||
| 7231 | 15936 | size_t Field_blob::get_key_image(uchar *buff, size_t length, | |
| 7232 | imagetype type_arg) const { | ||
| 7233 |
1/2✓ Branch 0 taken 15937 times.
✗ Branch 1 not taken.
|
15936 | uint32 blob_length = get_length(); |
| 7234 |
1/2✓ Branch 0 taken 15937 times.
✗ Branch 1 not taken.
|
15937 | const uchar *const blob = get_blob_data(); |
| 7235 | |||
| 7236 |
2/2✓ Branch 0 taken 467 times.
✓ Branch 1 taken 15470 times.
|
15937 | if (type_arg == itMBR) { |
| 7237 | 467 | const uint image_length = SIZEOF_STORED_DOUBLE * 4; | |
| 7238 | |||
| 7239 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 467 times.
|
467 | if (blob_length < SRID_SIZE) { |
| 7240 | ✗ | memset(buff, 0, image_length); | |
| 7241 | ✗ | return image_length; | |
| 7242 | } | ||
| 7243 | 467 | gis::srid_t srid = uint4korr(blob); | |
| 7244 | 467 | const dd::Spatial_reference_system *srs = nullptr; | |
| 7245 | dd::cache::Dictionary_client::Auto_releaser m_releaser( | ||
| 7246 |
2/4✓ Branch 0 taken 467 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 467 times.
✗ Branch 3 not taken.
|
467 | current_thd->dd_client()); |
| 7247 |
1/2✓ Branch 0 taken 467 times.
✗ Branch 1 not taken.
|
467 | Srs_fetcher fetcher(current_thd); |
| 7248 |
3/4✓ Branch 0 taken 35 times.
✓ Branch 1 taken 432 times.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
|
467 | if (srid != 0) fetcher.acquire(srid, &srs); |
| 7249 |
2/4✓ Branch 0 taken 467 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 467 times.
|
467 | if (get_mbr_from_store(srs, blob, blob_length, 2, |
| 7250 | pointer_cast<double *>(buff), &srid)) { | ||
| 7251 | ✗ | memset(buff, 0, image_length); | |
| 7252 | } else { | ||
| 7253 | // get_mbr_from_store returns the MBR in machine byte order, but buff | ||
| 7254 | // should always be in little-endian order. | ||
| 7255 | 467 | float8store(buff, *pointer_cast<double *>(buff)); | |
| 7256 | 467 | float8store(buff + 8, *(pointer_cast<double *>(buff) + 1)); | |
| 7257 | 467 | float8store(buff + 16, *(pointer_cast<double *>(buff) + 2)); | |
| 7258 | 467 | float8store(buff + 24, *(pointer_cast<double *>(buff) + 3)); | |
| 7259 | } | ||
| 7260 | |||
| 7261 | 467 | return image_length; | |
| 7262 | 467 | } | |
| 7263 | |||
| 7264 | 15470 | uint local_char_length = length / field_charset->mbmaxlen; | |
| 7265 |
2/2✓ Branch 0 taken 15469 times.
✓ Branch 1 taken 1 times.
|
15470 | local_char_length = blob == nullptr |
| 7266 | ? 0 | ||
| 7267 |
1/2✓ Branch 0 taken 15469 times.
✗ Branch 1 not taken.
|
15469 | : my_charpos(field_charset, blob, blob + blob_length, |
| 7268 | local_char_length); | ||
| 7269 | 15470 | blob_length = std::min(blob_length, local_char_length); | |
| 7270 | |||
| 7271 |
2/2✓ Branch 0 taken 10692 times.
✓ Branch 1 taken 4778 times.
|
15470 | if ((uint32)length > blob_length) { |
| 7272 | /* | ||
| 7273 | Must clear this as we do a memcmp in opt_range.cc to detect | ||
| 7274 | identical keys | ||
| 7275 | */ | ||
| 7276 | 10692 | memset(buff + HA_KEY_BLOB_LENGTH + blob_length, 0, (length - blob_length)); | |
| 7277 | 10692 | length = (uint)blob_length; | |
| 7278 | } | ||
| 7279 | 15470 | int2store(buff, static_cast<uint16>(length)); | |
| 7280 |
2/2✓ Branch 0 taken 15428 times.
✓ Branch 1 taken 42 times.
|
15470 | if (length > 0) memcpy(buff + HA_KEY_BLOB_LENGTH, blob, length); |
| 7281 | 15470 | return HA_KEY_BLOB_LENGTH + length; | |
| 7282 | } | ||
| 7283 | |||
| 7284 | ✗ | void Field_blob::set_key_image(const uchar *buff, size_t length) { | |
| 7285 | ✗ | length = uint2korr(buff); | |
| 7286 | ✗ | (void)Field_blob::store((const char *)buff + HA_KEY_BLOB_LENGTH, length, | |
| 7287 | field_charset); | ||
| 7288 | } | ||
| 7289 | |||
| 7290 | 29888 | int Field_blob::key_cmp(const uchar *key_ptr, uint max_key_length) const { | |
| 7291 |
1/2✓ Branch 0 taken 29888 times.
✗ Branch 1 not taken.
|
29888 | uint32 blob_length = get_length(ptr); |
| 7292 |
1/2✓ Branch 0 taken 29888 times.
✗ Branch 1 not taken.
|
29888 | const uchar *blob1 = get_blob_data(); |
| 7293 |
1/2✓ Branch 0 taken 29888 times.
✗ Branch 1 not taken.
|
29888 | const CHARSET_INFO *cs = charset(); |
| 7294 | 29888 | uint local_char_length = max_key_length / cs->mbmaxlen; | |
| 7295 | 29888 | local_char_length = | |
| 7296 |
1/2✓ Branch 0 taken 29888 times.
✗ Branch 1 not taken.
|
29888 | my_charpos(cs, blob1, blob1 + blob_length, local_char_length); |
| 7297 | 29888 | blob_length = min(blob_length, local_char_length); | |
| 7298 |
1/2✓ Branch 0 taken 29888 times.
✗ Branch 1 not taken.
|
29888 | return Field_blob::cmp(blob1, blob_length, key_ptr + HA_KEY_BLOB_LENGTH, |
| 7299 | 89664 | uint2korr(key_ptr)); | |
| 7300 | } | ||
| 7301 | |||
| 7302 | 1539 | int Field_blob::key_cmp(const uchar *a, const uchar *b) const { | |
| 7303 | 1539 | return Field_blob::cmp(a + HA_KEY_BLOB_LENGTH, uint2korr(a), | |
| 7304 | 3078 | b + HA_KEY_BLOB_LENGTH, uint2korr(b)); | |
| 7305 | } | ||
| 7306 | |||
| 7307 | /** | ||
| 7308 | Save the field metadata for blob fields. | ||
| 7309 | |||
| 7310 | Saves the pack length in the first byte of the field metadata array | ||
| 7311 | at index of *metadata_ptr. | ||
| 7312 | |||
| 7313 | @param metadata_ptr First byte of field metadata | ||
| 7314 | |||
| 7315 | @returns number of bytes written to metadata_ptr | ||
| 7316 | */ | ||
| 7317 | 2874743 | int Field_blob::do_save_field_metadata(uchar *metadata_ptr) const { | |
| 7318 |
1/2✓ Branch 0 taken 2874760 times.
✗ Branch 1 not taken.
|
2874743 | DBUG_TRACE; |
| 7319 | 2874760 | *metadata_ptr = pack_length_no_ptr(); | |
| 7320 |
5/8✓ Branch 0 taken 2874759 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2874756 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17 times.
✓ Branch 5 taken 2874739 times.
✓ Branch 6 taken 17 times.
✗ Branch 7 not taken.
|
2874755 | DBUG_PRINT("debug", ("metadata: %u (pack_length_no_ptr)", *metadata_ptr)); |
| 7321 | 2874734 | return 1; | |
| 7322 | 2874756 | } | |
| 7323 | |||
| 7324 | 10481 | size_t Field_blob::make_sort_key(uchar *to, size_t length) const { | |
| 7325 | static const uchar EMPTY_BLOB[1] = {0}; | ||
| 7326 | 10481 | uint32 blob_length = get_length(); | |
| 7327 | |||
| 7328 | 10481 | const int flags = | |
| 7329 |
2/2✓ Branch 0 taken 10233 times.
✓ Branch 1 taken 248 times.
|
10481 | (field_charset->pad_attribute == NO_PAD) ? 0 : MY_STRXFRM_PAD_TO_MAXLEN; |
| 7330 | |||
| 7331 |
2/2✓ Branch 0 taken 10427 times.
✓ Branch 1 taken 54 times.
|
10481 | const uchar *blob = blob_length > 0 ? get_blob_data() : EMPTY_BLOB; |
| 7332 | |||
| 7333 | 10481 | return field_charset->coll->strnxfrm(field_charset, to, length, length, blob, | |
| 7334 | 10481 | blob_length, flags); | |
| 7335 | } | ||
| 7336 | |||
| 7337 | 1228486 | void Field_blob::sql_type(String &res) const { | |
| 7338 | const char *str; | ||
| 7339 | uint length; | ||
| 7340 |
4/4✓ Branch 0 taken 8533 times.
✓ Branch 1 taken 536612 times.
✓ Branch 2 taken 383561 times.
✓ Branch 3 taken 299780 times.
|
1228486 | switch (packlength) { |
| 7341 | 8533 | default: | |
| 7342 | 8533 | str = "tiny"; | |
| 7343 | 8533 | length = 4; | |
| 7344 | 8533 | break; | |
| 7345 | 536612 | case 2: | |
| 7346 | 536612 | str = ""; | |
| 7347 | 536612 | length = 0; | |
| 7348 | 536612 | break; | |
| 7349 | 383561 | case 3: | |
| 7350 | 383561 | str = "medium"; | |
| 7351 | 383561 | length = 6; | |
| 7352 | 383561 | break; | |
| 7353 | 299780 | case 4: | |
| 7354 | 299780 | str = "long"; | |
| 7355 | 299780 | length = 4; | |
| 7356 | 299780 | break; | |
| 7357 | } | ||
| 7358 | 1228486 | res.set_ascii(str, length); | |
| 7359 |
2/2✓ Branch 0 taken 289119 times.
✓ Branch 1 taken 939368 times.
|
1228487 | if (charset() == &my_charset_bin) |
| 7360 | 289119 | res.append(STRING_WITH_LEN("blob")); | |
| 7361 | else { | ||
| 7362 | 939368 | res.append(STRING_WITH_LEN("text")); | |
| 7363 | } | ||
| 7364 | 1228487 | } | |
| 7365 | |||
| 7366 | ✗ | bool Field_blob::copy() { | |
| 7367 | ✗ | const uint32 length = get_length(); | |
| 7368 | ✗ | if (value.copy(pointer_cast<const char *>(get_blob_data()), length, | |
| 7369 | ✗ | charset())) { | |
| 7370 | ✗ | Field_blob::reset(); | |
| 7371 | ✗ | my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), length); | |
| 7372 | ✗ | return true; | |
| 7373 | } | ||
| 7374 | ✗ | assert(value.length() == length); | |
| 7375 | ✗ | set_ptr(length, pointer_cast<const uchar *>(value.ptr())); | |
| 7376 | ✗ | return false; | |
| 7377 | } | ||
| 7378 | |||
| 7379 | 997611 | uchar *Field_blob::pack(uchar *to, const uchar *from, size_t max_length) const { | |
| 7380 |
1/2✓ Branch 0 taken 997612 times.
✗ Branch 1 not taken.
|
997611 | uint32 length = get_length(from); // Length of from string |
| 7381 | |||
| 7382 | /* | ||
| 7383 | Store max length, which will occupy packlength bytes. | ||
| 7384 | */ | ||
| 7385 | uchar len_buf[4]; | ||
| 7386 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 997612 times.
|
997612 | assert(packlength <= sizeof(len_buf)); |
| 7387 |
1/2✓ Branch 0 taken 997612 times.
✗ Branch 1 not taken.
|
997612 | store_blob_length(len_buf, packlength, length); |
| 7388 | |||
| 7389 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 997612 times.
|
997612 | if (packlength >= max_length) { |
| 7390 | ✗ | memcpy(to, len_buf, max_length); | |
| 7391 | ✗ | return to + max_length; | |
| 7392 | } | ||
| 7393 | |||
| 7394 | 997612 | memcpy(to, len_buf, packlength); | |
| 7395 | |||
| 7396 | /* | ||
| 7397 | Store the actual blob data, which will occupy 'length' bytes. | ||
| 7398 | */ | ||
| 7399 | 997612 | size_t store_length = min<size_t>(length, max_length - packlength); | |
| 7400 |
2/2✓ Branch 0 taken 990358 times.
✓ Branch 1 taken 7254 times.
|
997612 | if (store_length > 0) { |
| 7401 | 990358 | memcpy(to + packlength, get_blob_data(from + packlength), store_length); | |
| 7402 | } | ||
| 7403 | |||
| 7404 | 997612 | return to + packlength + store_length; | |
| 7405 | } | ||
| 7406 | |||
| 7407 | 7016444 | uchar *Field_blob::pack_with_metadata_bytes(uchar *to, const uchar *from, | |
| 7408 | uint max_length) const { | ||
| 7409 |
1/2✓ Branch 0 taken 7016449 times.
✗ Branch 1 not taken.
|
7016444 | uint32 length = get_length(from); // Length of from string |
| 7410 | |||
| 7411 | /* | ||
| 7412 | Store max length, which will occupy packlength bytes. If the max | ||
| 7413 | length given is smaller than the actual length of the blob, we | ||
| 7414 | just store the initial bytes of the blob. | ||
| 7415 | */ | ||
| 7416 |
1/2✓ Branch 0 taken 7016438 times.
✗ Branch 1 not taken.
|
7016449 | store_blob_length(to, packlength, min(length, max_length)); |
| 7417 | |||
| 7418 | /* | ||
| 7419 | Store the actual blob data, which will occupy 'length' bytes. | ||
| 7420 | */ | ||
| 7421 |
2/2✓ Branch 0 taken 6991008 times.
✓ Branch 1 taken 25430 times.
|
7016438 | if (length > 0) { |
| 7422 | 6991008 | memcpy(to + packlength, get_blob_data(from + packlength), length); | |
| 7423 | } | ||
| 7424 | 7016438 | return to + packlength + length; | |
| 7425 | } | ||
| 7426 | |||
| 7427 | /** | ||
| 7428 | Unpack a blob field from row data. | ||
| 7429 | |||
| 7430 | This method is used to unpack a blob field from a master whose size of | ||
| 7431 | the field is less than that of the slave. Note: This method is included | ||
| 7432 | to satisfy inheritance rules, but is not needed for blob fields. It | ||
| 7433 | simply is used as a pass-through to the original unpack() method for | ||
| 7434 | blob fields. | ||
| 7435 | |||
| 7436 | @param from Source of the data | ||
| 7437 | @param param_data The "metadata", as stored in the Table_map_log_event | ||
| 7438 | for this field. This metadata is the number of bytes | ||
| 7439 | used to represent the length of the blob (1, 2, 3, or | ||
| 7440 | 4). | ||
| 7441 | |||
| 7442 | @return New pointer into memory based on from + length of the data | ||
| 7443 | */ | ||
| 7444 | 4997796 | const uchar *Field_blob::unpack(uchar *, const uchar *from, uint param_data) { | |
| 7445 |
1/2✓ Branch 0 taken 4997799 times.
✗ Branch 1 not taken.
|
4997796 | DBUG_TRACE; |
| 7446 |
3/8✓ Branch 0 taken 4997796 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4997798 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4997798 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
4997799 | DBUG_PRINT("enter", ("from: %p;" |
| 7447 | " param_data: %u; ", | ||
| 7448 | from, param_data)); | ||
| 7449 | 4997799 | uint const master_packlength = | |
| 7450 |
2/2✓ Branch 0 taken 198165 times.
✓ Branch 1 taken 4799634 times.
|
4997799 | param_data > 0 ? param_data & 0xFF : packlength; |
| 7451 |
1/2✓ Branch 0 taken 4997798 times.
✗ Branch 1 not taken.
|
4997799 | uint32 const length = get_length(from, master_packlength); |
| 7452 |
1/2✓ Branch 0 taken 4997798 times.
✗ Branch 1 not taken.
|
4997798 | DBUG_DUMP("packed", from, length + master_packlength); |
| 7453 | 4997798 | bitmap_set_bit(table->write_set, field_index()); | |
| 7454 |
1/2✓ Branch 0 taken 4997798 times.
✗ Branch 1 not taken.
|
4997797 | Field_blob::store(pointer_cast<const char *>(from) + master_packlength, |
| 7455 | length, field_charset); | ||
| 7456 |
1/2✓ Branch 0 taken 4997799 times.
✗ Branch 1 not taken.
|
4997798 | DBUG_DUMP("field", ptr, pack_length() /* len bytes + ptr bytes */); |
| 7457 |
2/4✓ Branch 0 taken 4997799 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4997799 times.
✗ Branch 3 not taken.
|
4997799 | DBUG_DUMP("value", get_blob_data(), length /* the blob value length */); |
| 7458 | 4997799 | return from + master_packlength + length; | |
| 7459 | 4997799 | } | |
| 7460 | |||
| 7461 | 438848 | uint Field_blob::max_packed_col_length() const { | |
| 7462 |
2/3✓ Branch 0 taken 257541 times.
✓ Branch 1 taken 181308 times.
✗ Branch 2 not taken.
|
438848 | switch (packlength) { |
| 7463 | 257541 | case 1: | |
| 7464 | case 2: | ||
| 7465 | case 3: | ||
| 7466 | 257541 | return packlength + (1u << (packlength * 8)) - 1; | |
| 7467 | 181308 | case 4: | |
| 7468 | 181308 | return UINT_MAX; | |
| 7469 | ✗ | default: | |
| 7470 | ✗ | assert(false); | |
| 7471 | return UINT_MAX; | ||
| 7472 | } | ||
| 7473 | } | ||
| 7474 | |||
| 7475 | 90517 | uint Field_blob::is_equal(const Create_field *new_field) const { | |
| 7476 |
1/2✓ Branch 0 taken 90517 times.
✗ Branch 1 not taken.
|
90517 | DBUG_TRACE; |
| 7477 | |||
| 7478 | // Can't use change_prevents_inplace() here as it uses | ||
| 7479 | // sql_type_prevents_inplace() which checks real_type(), and | ||
| 7480 | // Field_blob::real_type() does NOT return the actual blob type as | ||
| 7481 | // one could expect, so we have to check against | ||
| 7482 | // get_blob_type_from_length(max_data_length() instead. | ||
| 7483 | // length_prevents_inplace() is less strict than pack_length | ||
| 7484 | // equality so would be redundant here. | ||
| 7485 |
1/2✓ Branch 0 taken 90517 times.
✗ Branch 1 not taken.
|
90517 | if (new_field->sql_type != get_blob_type_from_length(max_data_length()) || |
| 7486 |
2/4✓ Branch 0 taken 90380 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 90380 times.
✗ Branch 3 not taken.
|
90380 | new_field->pack_length() != pack_length() || |
| 7487 |
9/10✓ Branch 0 taken 90380 times.
✓ Branch 1 taken 137 times.
✓ Branch 2 taken 90380 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 90374 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 15 times.
✓ Branch 7 taken 90359 times.
✓ Branch 8 taken 158 times.
✓ Branch 9 taken 90359 times.
|
271271 | charset_prevents_inplace(*this, *new_field) || |
| 7488 | 90374 | has_different_compression_attributes_with(*new_field)) { | |
| 7489 | 158 | return IS_EQUAL_NO; | |
| 7490 | } | ||
| 7491 | |||
| 7492 |
2/2✓ Branch 0 taken 90345 times.
✓ Branch 1 taken 14 times.
|
90359 | if (new_field->charset == field_charset) { |
| 7493 | 90345 | return IS_EQUAL_YES; | |
| 7494 | } | ||
| 7495 | |||
| 7496 | 14 | return IS_EQUAL_PACK_LENGTH; | |
| 7497 | 90517 | } | |
| 7498 | |||
| 7499 | 3421 | void Field_geom::sql_type(String &res) const { | |
| 7500 | 3421 | const CHARSET_INFO *cs = &my_charset_latin1; | |
| 7501 |
8/8✓ Branch 0 taken 1748 times.
✓ Branch 1 taken 131 times.
✓ Branch 2 taken 129 times.
✓ Branch 3 taken 90 times.
✓ Branch 4 taken 82 times.
✓ Branch 5 taken 78 times.
✓ Branch 6 taken 76 times.
✓ Branch 7 taken 1087 times.
|
3421 | switch (geom_type) { |
| 7502 | 1748 | case GEOM_POINT: | |
| 7503 | 1748 | res.set(STRING_WITH_LEN("point"), cs); | |
| 7504 | 1748 | break; | |
| 7505 | 131 | case GEOM_LINESTRING: | |
| 7506 | 131 | res.set(STRING_WITH_LEN("linestring"), cs); | |
| 7507 | 131 | break; | |
| 7508 | 129 | case GEOM_POLYGON: | |
| 7509 | 129 | res.set(STRING_WITH_LEN("polygon"), cs); | |
| 7510 | 129 | break; | |
| 7511 | 90 | case GEOM_MULTIPOINT: | |
| 7512 | 90 | res.set(STRING_WITH_LEN("multipoint"), cs); | |
| 7513 | 90 | break; | |
| 7514 | 82 | case GEOM_MULTILINESTRING: | |
| 7515 | 82 | res.set(STRING_WITH_LEN("multilinestring"), cs); | |
| 7516 | 82 | break; | |
| 7517 | 78 | case GEOM_MULTIPOLYGON: | |
| 7518 | 78 | res.set(STRING_WITH_LEN("multipolygon"), cs); | |
| 7519 | 78 | break; | |
| 7520 | 76 | case GEOM_GEOMETRYCOLLECTION: | |
| 7521 | 76 | res.set(STRING_WITH_LEN("geomcollection"), cs); | |
| 7522 | 76 | break; | |
| 7523 | 1087 | default: | |
| 7524 | 1087 | res.set(STRING_WITH_LEN("geometry"), cs); | |
| 7525 | } | ||
| 7526 | 3421 | } | |
| 7527 | |||
| 7528 | ✗ | type_conversion_status Field_geom::store(double) { | |
| 7529 | ✗ | my_error(ER_CANT_CREATE_GEOMETRY_OBJECT, MYF(0)); | |
| 7530 | ✗ | return TYPE_ERR_BAD_VALUE; | |
| 7531 | } | ||
| 7532 | |||
| 7533 | 5 | type_conversion_status Field_geom::store(longlong, bool) { | |
| 7534 | 5 | my_error(ER_CANT_CREATE_GEOMETRY_OBJECT, MYF(0)); | |
| 7535 | 5 | return TYPE_ERR_BAD_VALUE; | |
| 7536 | } | ||
| 7537 | |||
| 7538 | 2 | type_conversion_status Field_geom::store_decimal(const my_decimal *) { | |
| 7539 | 2 | my_error(ER_CANT_CREATE_GEOMETRY_OBJECT, MYF(0)); | |
| 7540 | 2 | return TYPE_ERR_BAD_VALUE; | |
| 7541 | } | ||
| 7542 | |||
| 7543 | 2476040 | type_conversion_status Field_geom::store(const char *from, size_t length, | |
| 7544 | const CHARSET_INFO *cs) { | ||
| 7545 |
2/2✓ Branch 0 taken 386 times.
✓ Branch 1 taken 2475654 times.
|
2476040 | if (length < SRID_SIZE + WKB_HEADER_SIZE + sizeof(uint32)) { |
| 7546 | 386 | Field_blob::reset(); | |
| 7547 | 386 | my_error(ER_CANT_CREATE_GEOMETRY_OBJECT, MYF(0)); | |
| 7548 | 386 | return TYPE_ERR_BAD_VALUE; | |
| 7549 | } | ||
| 7550 | |||
| 7551 | 2475654 | return Field_blob::store(from, length, cs); | |
| 7552 | } | ||
| 7553 | |||
| 7554 | 2498810 | type_conversion_status Field_geom::store_internal(const char *from, | |
| 7555 | size_t length, | ||
| 7556 | const CHARSET_INFO *cs) { | ||
| 7557 | // Check that the given WKB | ||
| 7558 | // 1. is at least 13 bytes long (length of GEOMETRYCOLLECTION EMPTY) | ||
| 7559 | // 2. isn't marked as bad geometry data | ||
| 7560 | // 3. isn't shorter than empty geometrycollection | ||
| 7561 | // 4. is a valid geometry type | ||
| 7562 | // 5. is well formed | ||
| 7563 |
2/2✓ Branch 0 taken 2498875 times.
✓ Branch 1 taken 95 times.
|
2498970 | if (length < 13 || // 1 |
| 7564 |
2/2✓ Branch 0 taken 2498871 times.
✓ Branch 1 taken 4 times.
|
4997691 | from == Geometry::bad_geometry_data.ptr() || // 2 |
| 7565 | 2498838 | length < SRID_SIZE + WKB_HEADER_SIZE + sizeof(uint32) || // 3 | |
| 7566 |
5/6✓ Branch 0 taken 2498816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2498573 times.
✓ Branch 3 taken 265 times.
✓ Branch 4 taken 419 times.
✓ Branch 5 taken 2498581 times.
|
7496422 | !Geometry::is_valid_geotype(uint4korr(from + SRID_SIZE + 1)) || // 4 |
| 7567 |
2/2✓ Branch 0 taken 61 times.
✓ Branch 1 taken 2498581 times.
|
2498573 | !Geometry::is_well_formed(from, length, // 5 |
| 7568 | geometry_type_to_wkb_type(geom_type), | ||
| 7569 | Geometry::wkb_ndr)) { | ||
| 7570 | 419 | Field_blob::reset(); | |
| 7571 | 419 | my_error(ER_CANT_CREATE_GEOMETRY_OBJECT, MYF(0)); | |
| 7572 | 419 | return TYPE_ERR_BAD_VALUE; | |
| 7573 | } | ||
| 7574 | |||
| 7575 | /* | ||
| 7576 | Check that the SRID of the geometry matches the expected SRID for this | ||
| 7577 | field | ||
| 7578 | */ | ||
| 7579 |
2/2✓ Branch 0 taken 1647907 times.
✓ Branch 1 taken 850595 times.
|
2498581 | if (get_srid().has_value()) { |
| 7580 | 1647907 | gis::srid_t geometry_srid = uint4korr(from); | |
| 7581 |
3/4✓ Branch 0 taken 1647835 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 1647824 times.
|
1648005 | if (geometry_srid != get_srid().value()) { |
| 7582 | 11 | Field_blob::reset(); | |
| 7583 | 11 | my_error(ER_WRONG_SRID_FOR_COLUMN, MYF(0), field_name, | |
| 7584 | static_cast<unsigned long>(geometry_srid), | ||
| 7585 |
2/4✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
|
11 | static_cast<unsigned long>(get_srid().value())); |
| 7586 | 11 | return TYPE_ERR_BAD_VALUE; | |
| 7587 | } | ||
| 7588 | } | ||
| 7589 | |||
| 7590 |
3/4✓ Branch 0 taken 2053418 times.
✓ Branch 1 taken 445001 times.
✓ Branch 2 taken 2053430 times.
✗ Branch 3 not taken.
|
2498419 | if (table->copy_blobs || length <= MAX_FIELD_WIDTH) { // Must make a copy |
| 7591 | 2498431 | value.copy(from, length, cs); | |
| 7592 | 2498536 | from = value.ptr(); | |
| 7593 | } | ||
| 7594 | |||
| 7595 | 2498569 | store_ptr_and_length(from, length); | |
| 7596 | 2498620 | return TYPE_OK; | |
| 7597 | } | ||
| 7598 | |||
| 7599 | 500 | uint Field_geom::is_equal(const Create_field *new_field) const { | |
| 7600 | 500 | return new_field->sql_type == real_type() && | |
| 7601 |
2/2✓ Branch 0 taken 483 times.
✓ Branch 1 taken 12 times.
|
495 | new_field->geom_type == get_geometry_type() && |
| 7602 |
3/4✓ Branch 0 taken 495 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 483 times.
✗ Branch 3 not taken.
|
1478 | new_field->charset == field_charset && |
| 7603 |
1/2✓ Branch 0 taken 483 times.
✗ Branch 1 not taken.
|
983 | new_field->pack_length() == pack_length(); |
| 7604 | } | ||
| 7605 | |||
| 7606 | /** | ||
| 7607 | Get the type of this field (json). | ||
| 7608 | @param str the string that receives the type | ||
| 7609 | */ | ||
| 7610 | 130278 | void Field_json::sql_type(String &str) const { | |
| 7611 | 130278 | str.set_ascii(STRING_WITH_LEN("json")); | |
| 7612 | 130278 | } | |
| 7613 | |||
| 7614 | /// Create a shallow clone of this field in the specified MEM_ROOT. | ||
| 7615 | 1071805 | Field_json *Field_json::clone(MEM_ROOT *mem_root) const { | |
| 7616 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1071804 times.
|
1071805 | assert(type() == MYSQL_TYPE_JSON); |
| 7617 |
1/2✓ Branch 0 taken 1071806 times.
✗ Branch 1 not taken.
|
1071804 | return new (mem_root) Field_json(*this); |
| 7618 | } | ||
| 7619 | |||
| 7620 | /** | ||
| 7621 | Check if a new field is compatible with this one. | ||
| 7622 | @param new_field the new field | ||
| 7623 | @return true if new_field is compatible with this field, false otherwise | ||
| 7624 | */ | ||
| 7625 | 4566 | uint Field_json::is_equal(const Create_field *new_field) const { | |
| 7626 | // All JSON fields are compatible with each other. | ||
| 7627 |
2/2✓ Branch 0 taken 4557 times.
✓ Branch 1 taken 9 times.
|
9123 | return (new_field->sql_type == real_type() && |
| 7628 |
1/2✓ Branch 0 taken 4557 times.
✗ Branch 1 not taken.
|
9123 | !has_different_compression_attributes_with(*new_field)); |
| 7629 | } | ||
| 7630 | |||
| 7631 | /** | ||
| 7632 | Store data in this JSON field. | ||
| 7633 | |||
| 7634 | JSON data is usually stored using store(Field_json*) or store_json(), so this | ||
| 7635 | function will only be called if non-JSON data is attempted stored in a JSON | ||
| 7636 | field. This results in an error in most cases. | ||
| 7637 | |||
| 7638 | It will attempt to parse the string (unless it's binary) as JSON text, and | ||
| 7639 | store a binary representation of JSON document if the string could be parsed. | ||
| 7640 | |||
| 7641 | Note that we override store() and not store_internal() because | ||
| 7642 | Field_blob::store() contains logic that bypasses store_internal() in | ||
| 7643 | some cases we care about. In particular: | ||
| 7644 | |||
| 7645 | - When supplied an empty string, we want to raise a JSON syntax | ||
| 7646 | error instead of silently inserting an empty byte string. | ||
| 7647 | |||
| 7648 | - When called from GROUP_CONCAT with ORDER BY or DISTINCT, we want | ||
| 7649 | to do the same data conversion as usual, whereas | ||
| 7650 | Field_blob::store() jumps directly to Field_blob::store_to_mem() | ||
| 7651 | with the unprocessed input data. | ||
| 7652 | |||
| 7653 | @param from the start of the data to be stored | ||
| 7654 | @param length the length of the data | ||
| 7655 | @param cs the character set of the data | ||
| 7656 | @return zero on success, non-zero on failure | ||
| 7657 | */ | ||
| 7658 | 130234 | type_conversion_status Field_json::store(const char *from, size_t length, | |
| 7659 | const CHARSET_INFO *cs) { | ||
| 7660 |
3/6✓ Branch 0 taken 130240 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130284 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 130377 times.
|
130234 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 7661 | |||
| 7662 | /* | ||
| 7663 | First clear the field so that it doesn't contain garbage if we | ||
| 7664 | return with an error. Some callers continue for a while even after | ||
| 7665 | an error has been raised, and they could get into trouble if the | ||
| 7666 | field contains garbage. | ||
| 7667 | */ | ||
| 7668 |
1/2✓ Branch 0 taken 130390 times.
✗ Branch 1 not taken.
|
130327 | reset(); |
| 7669 | |||
| 7670 | const char *s; | ||
| 7671 | size_t ss; | ||
| 7672 | 130390 | String v(from, length, cs); | |
| 7673 | |||
| 7674 |
3/4✓ Branch 0 taken 130304 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 130298 times.
|
130355 | if (ensure_utf8mb4(v, &value, &s, &ss, true)) { |
| 7675 | 6 | return TYPE_ERR_BAD_VALUE; | |
| 7676 | } | ||
| 7677 | |||
| 7678 | 130298 | const char *err_table_name = *table_name; | |
| 7679 | 130298 | const char *err_field_name = field_name; | |
| 7680 | std::unique_ptr<Json_dom> dom(Json_dom::parse( | ||
| 7681 | s, ss, | ||
| 7682 | 39 | [err_table_name, err_field_name](const char *parse_err, | |
| 7683 | 78 | size_t err_offset) { | |
| 7684 | 39 | String s_err; | |
| 7685 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | s_err.append(err_table_name); |
| 7686 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | s_err.append('.'); |
| 7687 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | s_err.append(err_field_name); |
| 7688 |
2/4✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
|
39 | my_error(ER_INVALID_JSON_TEXT, MYF(0), parse_err, err_offset, |
| 7689 | s_err.c_ptr_safe()); | ||
| 7690 | 39 | }, | |
| 7691 |
1/2✓ Branch 0 taken 130420 times.
✗ Branch 1 not taken.
|
260638 | JsonDocumentDefaultDepthHandler)); |
| 7692 | |||
| 7693 |
2/2✓ Branch 0 taken 39 times.
✓ Branch 1 taken 130390 times.
|
130442 | if (dom.get() == nullptr) return TYPE_ERR_BAD_VALUE; |
| 7694 | |||
| 7695 |
4/6✓ Branch 0 taken 130332 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 130346 times.
|
130390 | if (json_binary::serialize(current_thd, dom.get(), &value)) |
| 7696 | 3 | return TYPE_ERR_BAD_VALUE; | |
| 7697 | |||
| 7698 |
1/2✓ Branch 0 taken 130243 times.
✗ Branch 1 not taken.
|
130346 | return store_binary(value.ptr(), value.length()); |
| 7699 | 130291 | } | |
| 7700 | |||
| 7701 | /** | ||
| 7702 | Helper function for raising an error when trying to store a value | ||
| 7703 | into a JSON column, and that value needs to be cast to JSON before | ||
| 7704 | it can be stored. | ||
| 7705 | */ | ||
| 7706 | 40 | type_conversion_status Field_json::unsupported_conversion() { | |
| 7707 |
3/6✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
|
40 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 7708 | 40 | String s; | |
| 7709 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | s.append(*table_name); |
| 7710 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | s.append('.'); |
| 7711 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | s.append(field_name); |
| 7712 |
2/4✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
|
40 | my_error(ER_INVALID_JSON_TEXT, MYF(0), "not a JSON text, may need CAST", 0, |
| 7713 | s.c_ptr_safe()); | ||
| 7714 | 40 | return TYPE_ERR_BAD_VALUE; | |
| 7715 | 40 | } | |
| 7716 | |||
| 7717 | /** | ||
| 7718 | Store the provided JSON binary data in this field. | ||
| 7719 | |||
| 7720 | @param[in] data pointer to JSON binary data | ||
| 7721 | @param[in] length the length of the binary data | ||
| 7722 | @return zero on success, non-zero on failure | ||
| 7723 | */ | ||
| 7724 | 453635 | type_conversion_status Field_json::store_binary(const char *data, | |
| 7725 | size_t length) { | ||
| 7726 | /* | ||
| 7727 | We expect that a valid binary representation of a JSON document is | ||
| 7728 | passed to us. | ||
| 7729 | */ | ||
| 7730 |
2/4✓ Branch 0 taken 453875 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 453875 times.
|
453635 | assert(json_binary::parse_binary(data, length).is_valid()); |
| 7731 | |||
| 7732 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 453875 times.
|
453875 | if (length > UINT_MAX32) { |
| 7733 | /* purecov: begin inspected */ | ||
| 7734 | ✗ | my_error(ER_JSON_VALUE_TOO_BIG, MYF(0)); | |
| 7735 | ✗ | return TYPE_ERR_BAD_VALUE; | |
| 7736 | /* purecov: end */ | ||
| 7737 | } | ||
| 7738 | |||
| 7739 | 453875 | return Field_blob::store(data, length, field_charset); | |
| 7740 | } | ||
| 7741 | |||
| 7742 | /// Store a double in a JSON field. Will raise an error for now. | ||
| 7743 | 10 | type_conversion_status Field_json::store(double) { | |
| 7744 | 10 | return unsupported_conversion(); | |
| 7745 | } | ||
| 7746 | |||
| 7747 | /// Store an integer in a JSON field. Will raise an error for now. | ||
| 7748 | 14 | type_conversion_status Field_json::store(longlong, bool) { | |
| 7749 | 14 | return unsupported_conversion(); | |
| 7750 | } | ||
| 7751 | |||
| 7752 | /// Store a decimal in a JSON field. Will raise an error for now. | ||
| 7753 | 7 | type_conversion_status Field_json::store_decimal(const my_decimal *) { | |
| 7754 | 7 | return unsupported_conversion(); | |
| 7755 | } | ||
| 7756 | |||
| 7757 | /// Store a TIME value in a JSON field. Will raise an error for now. | ||
| 7758 | 9 | type_conversion_status Field_json::store_time(MYSQL_TIME *, uint8) { | |
| 7759 | 9 | return unsupported_conversion(); | |
| 7760 | } | ||
| 7761 | |||
| 7762 | /** | ||
| 7763 | Store a JSON value as binary. | ||
| 7764 | |||
| 7765 | @param json the JSON value to store | ||
| 7766 | @return zero on success, non-zero otherwise | ||
| 7767 | */ | ||
| 7768 | 53999 | type_conversion_status Field_json::store_json(const Json_wrapper *json) { | |
| 7769 |
4/6✓ Branch 0 taken 53999 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53996 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 53996 times.
|
53999 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 7770 | |||
| 7771 | /* | ||
| 7772 | We want to serialize the JSON value directly into Field_blob::value if | ||
| 7773 | possible, so that we don't have to copy it there afterwards. | ||
| 7774 | |||
| 7775 | If the Json_wrapper is pointing to a document that already lives in | ||
| 7776 | Field_blob::value, it isn't safe to do so, since the source buffer and | ||
| 7777 | destination buffer is the same. This can happen if an UPDATE statement | ||
| 7778 | updates the same JSON column twice and the second update of the column | ||
| 7779 | reads data that the first update wrote to the output buffer. For example: | ||
| 7780 | |||
| 7781 | UPDATE t SET json_col = <something>, json_col = json_col->'$.path' | ||
| 7782 | |||
| 7783 | In that case, we serialize into a temporary string, which is later copied | ||
| 7784 | into Field_blob::value by store_binary(). | ||
| 7785 | */ | ||
| 7786 | 53999 | StringBuffer<STRING_BUFFER_USUAL_SIZE> tmpstr; | |
| 7787 |
3/4✓ Branch 0 taken 53999 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 155 times.
✓ Branch 3 taken 53844 times.
|
53999 | String *buffer = json->is_binary_backed_by(&value) ? &tmpstr : &value; |
| 7788 | |||
| 7789 |
4/6✓ Branch 0 taken 53999 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53999 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 53991 times.
|
53999 | if (json->to_binary(current_thd, buffer)) return TYPE_ERR_BAD_VALUE; |
| 7790 | |||
| 7791 |
1/2✓ Branch 0 taken 53991 times.
✗ Branch 1 not taken.
|
53991 | return store_binary(buffer->ptr(), buffer->length()); |
| 7792 | 53999 | } | |
| 7793 | |||
| 7794 | /** | ||
| 7795 | Copy the contents of a non-null JSON field into this field. | ||
| 7796 | |||
| 7797 | @param[in] field the field to copy data from | ||
| 7798 | @return zero on success, non-zero on failure | ||
| 7799 | */ | ||
| 7800 | 269495 | type_conversion_status Field_json::store(const Field_json *field) { | |
| 7801 | /* | ||
| 7802 | The callers of this function have already checked for null, so we | ||
| 7803 | don't need to handle it here for now. Assert that field is not | ||
| 7804 | null. | ||
| 7805 | */ | ||
| 7806 |
2/4✓ Branch 0 taken 269495 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 269495 times.
|
269495 | assert(!field->is_null()); |
| 7807 | |||
| 7808 | 269495 | String tmp; | |
| 7809 |
1/2✓ Branch 0 taken 269496 times.
✗ Branch 1 not taken.
|
269495 | String *s = field->Field_blob::val_str(&tmp, &tmp); |
| 7810 |
1/2✓ Branch 0 taken 269494 times.
✗ Branch 1 not taken.
|
538991 | return store_binary(s->ptr(), s->length()); |
| 7811 | 269494 | } | |
| 7812 | |||
| 7813 | 1043696 | bool Field_json::val_json(Json_wrapper *wr) const { | |
| 7814 |
1/2✓ Branch 0 taken 1044023 times.
✗ Branch 1 not taken.
|
1043696 | DBUG_TRACE; |
| 7815 |
4/6✓ Branch 0 taken 1044023 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1044011 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1043999 times.
|
1044023 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 7816 | |||
| 7817 | 1044011 | String tmp; | |
| 7818 |
1/2✓ Branch 0 taken 1043977 times.
✗ Branch 1 not taken.
|
1043981 | String *s = Field_blob::val_str(&tmp, &tmp); |
| 7819 | |||
| 7820 |
1/2✓ Branch 0 taken 1044025 times.
✗ Branch 1 not taken.
|
1043977 | json_binary::Value v(json_binary::parse_binary(s->ptr(), s->length())); |
| 7821 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1043941 times.
|
1044025 | if (v.type() == json_binary::Value::ERROR) { |
| 7822 | /* purecov: begin inspected */ | ||
| 7823 | ✗ | my_error(ER_INVALID_JSON_BINARY_DATA, MYF(0)); | |
| 7824 | ✗ | return true; | |
| 7825 | /* purecov: end */ | ||
| 7826 | } | ||
| 7827 | |||
| 7828 |
1/2✓ Branch 0 taken 1043762 times.
✗ Branch 1 not taken.
|
1043941 | *wr = Json_wrapper(v); |
| 7829 | 1043907 | return false; | |
| 7830 | 1043907 | } | |
| 7831 | |||
| 7832 | 397 | longlong Field_json::val_int() const { | |
| 7833 |
3/6✓ Branch 0 taken 397 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 397 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 397 times.
|
397 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 7834 | |||
| 7835 | 397 | Json_wrapper wr; | |
| 7836 |
2/4✓ Branch 0 taken 397 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 397 times.
|
397 | if (val_json(&wr)) return 0; /* purecov: inspected */ |
| 7837 | |||
| 7838 |
1/2✓ Branch 0 taken 397 times.
✗ Branch 1 not taken.
|
397 | return wr.coerce_int(field_name); |
| 7839 | 397 | } | |
| 7840 | |||
| 7841 | 455 | double Field_json::val_real() const { | |
| 7842 |
3/6✓ Branch 0 taken 455 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 455 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 455 times.
|
455 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 7843 | |||
| 7844 | 455 | Json_wrapper wr; | |
| 7845 |
2/4✓ Branch 0 taken 455 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 455 times.
|
455 | if (val_json(&wr)) return 0.0; /* purecov: inspected */ |
| 7846 | |||
| 7847 |
1/2✓ Branch 0 taken 455 times.
✗ Branch 1 not taken.
|
455 | return wr.coerce_real(field_name); |
| 7848 | 455 | } | |
| 7849 | |||
| 7850 | 167264 | String *Field_json::val_str(String *buf1, String *) const { | |
| 7851 |
4/6✓ Branch 0 taken 167264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 167259 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 167259 times.
|
167264 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 7852 | |||
| 7853 | /* | ||
| 7854 | Per contract of Field::val_str(String*,String*), buf1 should be | ||
| 7855 | used if the value needs to be converted to string, and buf2 should | ||
| 7856 | be used if the string value is already known. We need to convert, | ||
| 7857 | so use buf1. | ||
| 7858 | */ | ||
| 7859 | 167264 | buf1->length(0); | |
| 7860 | |||
| 7861 | 167264 | Json_wrapper wr; | |
| 7862 |
2/4✓ Branch 0 taken 167264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 167264 times.
✗ Branch 3 not taken.
|
334528 | if (val_json(&wr) || |
| 7863 |
6/10✓ Branch 0 taken 167264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 167261 times.
✓ Branch 4 taken 167264 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 167261 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
334528 | wr.to_string(buf1, true, field_name, JsonDocumentDefaultDepthHandler)) |
| 7864 | 3 | buf1->length(0); | |
| 7865 | |||
| 7866 | 167264 | return buf1; | |
| 7867 | 167264 | } | |
| 7868 | |||
| 7869 | 64 | my_decimal *Field_json::val_decimal(my_decimal *decimal_value) const { | |
| 7870 |
3/6✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 64 times.
|
64 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 7871 | |||
| 7872 | 64 | Json_wrapper wr; | |
| 7873 |
2/4✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 64 times.
|
64 | if (val_json(&wr)) { |
| 7874 | /* purecov: begin inspected */ | ||
| 7875 | ✗ | my_decimal_set_zero(decimal_value); | |
| 7876 | ✗ | return decimal_value; | |
| 7877 | /* purecov: end */ | ||
| 7878 | } | ||
| 7879 | |||
| 7880 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | return wr.coerce_decimal(decimal_value, field_name); |
| 7881 | 64 | } | |
| 7882 | |||
| 7883 | 17762 | bool Field_json::pack_diff(uchar **to, ulonglong value_format) const { | |
| 7884 |
1/2✓ Branch 0 taken 17762 times.
✗ Branch 1 not taken.
|
17762 | DBUG_TRACE; |
| 7885 | |||
| 7886 | const Json_diff_vector *diff_vector; | ||
| 7887 |
1/2✓ Branch 0 taken 17762 times.
✗ Branch 1 not taken.
|
17762 | get_diff_vector_and_length(value_format, &diff_vector); |
| 7888 |
2/2✓ Branch 0 taken 15195 times.
✓ Branch 1 taken 2567 times.
|
17762 | if (diff_vector == nullptr) return true; |
| 7889 | |||
| 7890 | // We know the caller has allocated enough space, but we don't | ||
| 7891 | // know how much it is. So just say that it is large, to | ||
| 7892 | // suppress bounds checks. | ||
| 7893 | 2567 | String to_string((char *)*to, 0xffffFFFF, &my_charset_bin); | |
| 7894 | 2567 | to_string.length(0); | |
| 7895 |
2/4✓ Branch 0 taken 2567 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2567 times.
|
2567 | if (diff_vector->write_binary(&to_string)) |
| 7896 | // write_binary only returns true (error) in case it failed to | ||
| 7897 | // allocate memory. But now we know it will not try to | ||
| 7898 | // allocate. | ||
| 7899 | ✗ | assert(0); /* purecov: inspected */ | |
| 7900 | |||
| 7901 | // It should not have reallocated. | ||
| 7902 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2567 times.
|
2567 | assert(*to == (uchar *)to_string.ptr()); |
| 7903 | |||
| 7904 | 2567 | *to += to_string.length(); | |
| 7905 | 2567 | return false; | |
| 7906 | 17762 | } | |
| 7907 | |||
| 7908 | 10044 | bool Field_json::is_before_image_equal_to_after_image() const { | |
| 7909 | 10044 | ptrdiff_t row_offset = table->record[1] - table->record[0]; | |
| 7910 |
2/2✓ Branch 0 taken 3917 times.
✓ Branch 1 taken 6127 times.
|
10044 | if (get_length(row_offset) != get_length()) return false; |
| 7911 |
2/2✓ Branch 0 taken 4064 times.
✓ Branch 1 taken 2063 times.
|
6127 | if (cmp(ptr, ptr + row_offset) != 0) return false; |
| 7912 | 2063 | return true; | |
| 7913 | } | ||
| 7914 | |||
| 7915 | 27744 | longlong Field_json::get_diff_vector_and_length( | |
| 7916 | ulonglong value_options, const Json_diff_vector **diff_vector_p) const { | ||
| 7917 |
1/2✓ Branch 0 taken 27744 times.
✗ Branch 1 not taken.
|
27744 | DBUG_TRACE; |
| 7918 | |||
| 7919 |
3/4✓ Branch 0 taken 27744 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2133 times.
✓ Branch 3 taken 25611 times.
|
27744 | if (is_null()) { |
| 7920 |
3/8✓ Branch 0 taken 2133 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2133 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2133 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
2133 | DBUG_PRINT("info", ("Returning 0 because field is NULL")); |
| 7921 |
2/2✓ Branch 0 taken 266 times.
✓ Branch 1 taken 1867 times.
|
2133 | if (diff_vector_p) *diff_vector_p = nullptr; |
| 7922 | 2133 | return 0; | |
| 7923 | } | ||
| 7924 | |||
| 7925 |
1/2✓ Branch 0 taken 25611 times.
✗ Branch 1 not taken.
|
25611 | longlong length_of_full_format = get_length(); |
| 7926 | 25611 | longlong length = -1; | |
| 7927 | 25611 | const Json_diff_vector *diff_vector = nullptr; | |
| 7928 | // Is the partial update smaller than the full update? | ||
| 7929 |
3/8✓ Branch 0 taken 25611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25611 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 25611 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
25611 | DBUG_PRINT("info", ("length_of_full_format=%lu", |
| 7930 | (unsigned long)length_of_full_format)); | ||
| 7931 | |||
| 7932 | // Is partial JSON updates enabled at all? | ||
| 7933 |
2/2✓ Branch 0 taken 14157 times.
✓ Branch 1 taken 11454 times.
|
25611 | if ((value_options & PARTIAL_JSON_UPDATES) == 0) { |
| 7934 |
3/8✓ Branch 0 taken 14157 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14157 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14157 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
14157 | DBUG_PRINT("info", ("Using full JSON format because " |
| 7935 | "binlog_row_value_format does not include " | ||
| 7936 | "PARTIAL_JSON")); | ||
| 7937 | 14157 | length = length_of_full_format; | |
| 7938 | } else { | ||
| 7939 | // Was the optimizer able to compute a partial update? | ||
| 7940 |
1/2✓ Branch 0 taken 11454 times.
✗ Branch 1 not taken.
|
11454 | diff_vector = table->get_logical_diffs(this); |
| 7941 |
2/2✓ Branch 0 taken 4851 times.
✓ Branch 1 taken 6603 times.
|
11454 | if (diff_vector == nullptr) { |
| 7942 | // Are before-image and after-image equal? | ||
| 7943 |
3/4✓ Branch 0 taken 4851 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2001 times.
✓ Branch 3 taken 2850 times.
|
4851 | if (is_before_image_equal_to_after_image()) { |
| 7944 |
3/8✓ Branch 0 taken 2001 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2001 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2001 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
2001 | DBUG_PRINT("info", ("Using empty Json_diff_vector because before-image " |
| 7945 | "is different from after-image.")); | ||
| 7946 | 2001 | diff_vector = &Json_diff_vector::EMPTY_JSON_DIFF_VECTOR; | |
| 7947 |
1/2✓ Branch 0 taken 2001 times.
✗ Branch 1 not taken.
|
2001 | length = diff_vector->binary_length(); |
| 7948 | } else { | ||
| 7949 |
3/8✓ Branch 0 taken 2850 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2850 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2850 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
2850 | DBUG_PRINT("info", |
| 7950 | ("Using full JSON format because there is no diff vector " | ||
| 7951 | "and before-image is different from after-image.")); | ||
| 7952 | 2850 | length = length_of_full_format; | |
| 7953 | } | ||
| 7954 | } else { | ||
| 7955 |
1/2✓ Branch 0 taken 6603 times.
✗ Branch 1 not taken.
|
6603 | longlong length_of_diff_vector = diff_vector->binary_length(); |
| 7956 | longlong length_of_empty_diff_vector = | ||
| 7957 |
1/2✓ Branch 0 taken 6603 times.
✗ Branch 1 not taken.
|
6603 | Json_diff_vector::EMPTY_JSON_DIFF_VECTOR.binary_length(); |
| 7958 |
3/8✓ Branch 0 taken 6603 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6603 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6603 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
6603 | DBUG_PRINT("info", ("length_of_diff_vector=%lu diff_vector->size()=%u", |
| 7959 | (unsigned long)length_of_diff_vector, | ||
| 7960 | (uint)diff_vector->size())); | ||
| 7961 | |||
| 7962 | // If the vector is empty, no need to do the expensive comparison | ||
| 7963 | // between before-image and after-image. | ||
| 7964 |
2/2✓ Branch 0 taken 1410 times.
✓ Branch 1 taken 5193 times.
|
6603 | if (length_of_diff_vector == length_of_empty_diff_vector) { |
| 7965 |
3/8✓ Branch 0 taken 1410 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1410 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1410 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
1410 | DBUG_PRINT("info", |
| 7966 | ("Using empty Json_diff_vector provided by optimizer.")); | ||
| 7967 | 1410 | length = length_of_diff_vector; | |
| 7968 | } | ||
| 7969 | // Are the before-image and the after-image equal? (This can | ||
| 7970 | // happen despite having a nonempty diff vector, in case | ||
| 7971 | // optimizer does not detect the equality) | ||
| 7972 |
3/4✓ Branch 0 taken 5193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 5131 times.
|
5193 | else if (is_before_image_equal_to_after_image()) { |
| 7973 |
3/8✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
62 | DBUG_PRINT("info", ("Using Json_diff_vector::EMPTY_JSON_DIFF_VECTOR " |
| 7974 | "because the before-image equals the after-image " | ||
| 7975 | "but the diff vector provided by the optimizer " | ||
| 7976 | "is non-empty.")); | ||
| 7977 | 62 | diff_vector = &Json_diff_vector::EMPTY_JSON_DIFF_VECTOR; | |
| 7978 | 62 | length = length_of_diff_vector; | |
| 7979 | } | ||
| 7980 | // Is the diff vector better than the full format? | ||
| 7981 |
2/2✓ Branch 0 taken 4949 times.
✓ Branch 1 taken 182 times.
|
5131 | else if (length_of_diff_vector < length_of_full_format) { |
| 7982 |
3/8✓ Branch 0 taken 4949 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4949 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4949 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
4949 | DBUG_PRINT("info", ("Using non-empty Json_diff_vector provided by " |
| 7983 | "optimizer because it is smaller than " | ||
| 7984 | "full format.")); | ||
| 7985 | 4949 | length = length_of_diff_vector; | |
| 7986 | } else { | ||
| 7987 |
3/8✓ Branch 0 taken 182 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 182 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 182 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
182 | DBUG_PRINT("info", |
| 7988 | ("Using full JSON format because diff vector was not " | ||
| 7989 | "smaller.")); | ||
| 7990 | 182 | diff_vector = nullptr; | |
| 7991 | 182 | length = length_of_full_format; | |
| 7992 | } | ||
| 7993 | } | ||
| 7994 | } | ||
| 7995 | |||
| 7996 | /* | ||
| 7997 | Can be equal to zero in the corner case where user inserted NULL | ||
| 7998 | value in a JSON NOT NULL column in non-strict mode. The server | ||
| 7999 | will store this as a zero-length non-NULL object, and interpret it | ||
| 8000 | as a JSON 'null' literal. | ||
| 8001 | */ | ||
| 8002 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25611 times.
|
25611 | assert(length >= 0); |
| 8003 | |||
| 8004 |
2/2✓ Branch 0 taken 20740 times.
✓ Branch 1 taken 4871 times.
|
25611 | if (diff_vector_p != nullptr) *diff_vector_p = diff_vector; |
| 8005 | 25611 | return length; | |
| 8006 | 27744 | } | |
| 8007 | |||
| 8008 | 1928 | bool Field_json::unpack_diff(const uchar **from) { | |
| 8009 |
1/2✓ Branch 0 taken 1928 times.
✗ Branch 1 not taken.
|
1928 | DBUG_TRACE; |
| 8010 | |||
| 8011 | // Use a temporary mem_root so that the thread does not hold the | ||
| 8012 | // memory for the Json_diff_vector until the end of the statement. | ||
| 8013 | 1928 | int memory_page_size = my_getpagesize(); | |
| 8014 | MEM_ROOT mem_root(key_memory_Slave_applier_json_diff_vector, | ||
| 8015 | 1928 | memory_page_size); | |
| 8016 | |||
| 8017 |
1/2✓ Branch 0 taken 1928 times.
✗ Branch 1 not taken.
|
1928 | Json_diff_vector diff_vector{Json_diff_vector::allocator_type(&mem_root)}; |
| 8018 | |||
| 8019 | // The caller should have verified that the buffer at 'from' is | ||
| 8020 | // sufficiently big to hold the whole diff_vector. | ||
| 8021 |
3/4✓ Branch 0 taken 1928 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 81 times.
✓ Branch 3 taken 1847 times.
|
1928 | if (diff_vector.read_binary(pointer_cast<const char **>(from), table, |
| 8022 | field_name)) | ||
| 8023 | 81 | return true; | |
| 8024 | |||
| 8025 | // Apply | ||
| 8026 |
4/6✓ Branch 0 taken 1847 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 1811 times.
✗ Branch 5 not taken.
|
1847 | switch (apply_json_diffs(this, &diff_vector)) { |
| 8027 | 27 | case enum_json_diff_status::REJECTED: | |
| 8028 | 27 | my_error(ER_COULD_NOT_APPLY_JSON_DIFF, MYF(0), | |
| 8029 |
1/2✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
|
27 | (int)table->s->table_name.length, table->s->table_name.str, |
| 8030 | field_name); | ||
| 8031 | 27 | return true; | |
| 8032 | 9 | case enum_json_diff_status::ERROR: | |
| 8033 | 9 | return true; /* purecov: inspected */ | |
| 8034 | 1811 | case enum_json_diff_status::SUCCESS: | |
| 8035 | 1811 | break; | |
| 8036 | } | ||
| 8037 | 1811 | return false; | |
| 8038 | 1928 | } | |
| 8039 | |||
| 8040 | 138 | bool Field_json::get_date(MYSQL_TIME *ltime, my_time_flags_t) const { | |
| 8041 |
3/6✓ Branch 0 taken 138 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 138 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 138 times.
|
138 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 8042 | |||
| 8043 | 138 | Json_wrapper wr; | |
| 8044 |
5/8✓ Branch 0 taken 138 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 138 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 123 times.
✓ Branch 7 taken 15 times.
|
138 | bool result = val_json(&wr) || wr.coerce_date(ltime, field_name); |
| 8045 |
2/2✓ Branch 0 taken 123 times.
✓ Branch 1 taken 15 times.
|
138 | if (result) |
| 8046 |
1/2✓ Branch 0 taken 123 times.
✗ Branch 1 not taken.
|
123 | set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME); /* purecov: inspected */ |
| 8047 | 138 | return result; | |
| 8048 | 138 | } | |
| 8049 | |||
| 8050 | 62 | bool Field_json::get_time(MYSQL_TIME *ltime) const { | |
| 8051 |
3/6✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
|
62 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 8052 | |||
| 8053 | 62 | Json_wrapper wr; | |
| 8054 |
5/8✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 62 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 58 times.
✓ Branch 7 taken 4 times.
|
62 | bool result = val_json(&wr) || wr.coerce_time(ltime, field_name); |
| 8055 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 4 times.
|
62 | if (result) |
| 8056 |
1/2✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
|
58 | set_zero_time(ltime, MYSQL_TIMESTAMP_TIME); /* purecov: inspected */ |
| 8057 | 62 | return result; | |
| 8058 | 62 | } | |
| 8059 | |||
| 8060 | 21019 | int Field_json::cmp_binary(const uchar *a_ptr, const uchar *b_ptr, | |
| 8061 | uint32 /* max_length */) const { | ||
| 8062 | 21019 | const char *a = pointer_cast<char *>(get_blob_data(a_ptr + packlength)); | |
| 8063 | 21019 | const char *b = pointer_cast<char *>(get_blob_data(b_ptr + packlength)); | |
| 8064 |
1/2✓ Branch 0 taken 21019 times.
✗ Branch 1 not taken.
|
21019 | uint32 a_length = get_length(a_ptr); |
| 8065 |
1/2✓ Branch 0 taken 21019 times.
✗ Branch 1 not taken.
|
21019 | uint32 b_length = get_length(b_ptr); |
| 8066 |
2/4✓ Branch 0 taken 21019 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21019 times.
✗ Branch 3 not taken.
|
21019 | Json_wrapper aw(json_binary::parse_binary(a, a_length)); |
| 8067 |
2/4✓ Branch 0 taken 21019 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21019 times.
✗ Branch 3 not taken.
|
21019 | Json_wrapper bw(json_binary::parse_binary(b, b_length)); |
| 8068 |
1/2✓ Branch 0 taken 21019 times.
✗ Branch 1 not taken.
|
42038 | return aw.compare(bw); |
| 8069 | 21019 | } | |
| 8070 | |||
| 8071 | 303 | size_t Field_json::make_sort_key(uchar *to, size_t length) const { | |
| 8072 | 303 | Json_wrapper wr; | |
| 8073 |
2/4✓ Branch 0 taken 303 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 303 times.
|
303 | if (val_json(&wr)) { |
| 8074 | ✗ | return 0; | |
| 8075 | } | ||
| 8076 |
1/2✓ Branch 0 taken 303 times.
✗ Branch 1 not taken.
|
303 | return wr.make_sort_key(to, length); |
| 8077 | 303 | } | |
| 8078 | |||
| 8079 | 2674 | ulonglong Field_json::make_hash_key(ulonglong hash_val) const { | |
| 8080 | 2674 | Json_wrapper wr; | |
| 8081 |
2/4✓ Branch 0 taken 2674 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2674 times.
|
2674 | if (val_json(&wr)) return hash_val; /* purecov: inspected */ |
| 8082 |
1/2✓ Branch 0 taken 2674 times.
✗ Branch 1 not taken.
|
2674 | return wr.make_hash_key(hash_val); |
| 8083 | 2674 | } | |
| 8084 | |||
| 8085 | 28369 | const char *Field_json::get_binary(ptrdiff_t row_offset) const { | |
| 8086 | 28369 | return pointer_cast<char *>(get_blob_data(ptr + packlength + row_offset)); | |
| 8087 | } | ||
| 8088 | |||
| 8089 | /**************************************************************************** | ||
| 8090 | ** enum type. | ||
| 8091 | ** This is a string which only can have a selection of different values. | ||
| 8092 | ** If one uses this string in a number context one gets the type number. | ||
| 8093 | ****************************************************************************/ | ||
| 8094 | |||
| 8095 | 255886 | enum ha_base_keytype Field_enum::key_type() const { | |
| 8096 |
4/5✓ Branch 0 taken 255732 times.
✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 28 times.
✓ Branch 4 taken 21 times.
|
255886 | switch (packlength) { |
| 8097 | 255732 | default: | |
| 8098 | 255732 | return HA_KEYTYPE_BINARY; | |
| 8099 | 105 | case 2: | |
| 8100 | 105 | return HA_KEYTYPE_USHORT_INT; | |
| 8101 | ✗ | case 3: | |
| 8102 | ✗ | return HA_KEYTYPE_UINT24; | |
| 8103 | 28 | case 4: | |
| 8104 | 28 | return HA_KEYTYPE_ULONG_INT; | |
| 8105 | 21 | case 8: | |
| 8106 | 21 | return HA_KEYTYPE_ULONGLONG; | |
| 8107 | } | ||
| 8108 | } | ||
| 8109 | |||
| 8110 | 158366577 | void Field_enum::store_type(ulonglong value) { | |
| 8111 |
4/6✓ Branch 0 taken 156643452 times.
✓ Branch 1 taken 11174 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 250 times.
✓ Branch 4 taken 1711703 times.
✗ Branch 5 not taken.
|
158366577 | switch (packlength) { |
| 8112 | 156643452 | case 1: | |
| 8113 | 156643452 | ptr[0] = (uchar)value; | |
| 8114 | 156643452 | break; | |
| 8115 | 11174 | case 2: | |
| 8116 |
1/2✓ Branch 0 taken 11174 times.
✗ Branch 1 not taken.
|
11174 | if (table->s->db_low_byte_first) |
| 8117 | 11174 | int2store(ptr, (unsigned short)value); | |
| 8118 | else | ||
| 8119 | ✗ | shortstore(ptr, (unsigned short)value); | |
| 8120 | 11174 | break; | |
| 8121 | ✗ | case 3: | |
| 8122 | ✗ | int3store(ptr, (long)value); | |
| 8123 | ✗ | break; | |
| 8124 | 250 | case 4: | |
| 8125 |
1/2✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
|
250 | if (table->s->db_low_byte_first) |
| 8126 | 250 | int4store(ptr, value); | |
| 8127 | else | ||
| 8128 | ✗ | longstore(ptr, (long)value); | |
| 8129 | 250 | break; | |
| 8130 | 1711703 | case 8: | |
| 8131 |
1/2✓ Branch 0 taken 1711703 times.
✗ Branch 1 not taken.
|
1711703 | if (table->s->db_low_byte_first) |
| 8132 | 1711703 | int8store(ptr, value); | |
| 8133 | else | ||
| 8134 | ✗ | longlongstore(ptr, value); | |
| 8135 | 1711703 | break; | |
| 8136 | } | ||
| 8137 | 158366577 | } | |
| 8138 | |||
| 8139 | /** | ||
| 8140 | @note | ||
| 8141 | Storing a empty string in a enum field gives a warning | ||
| 8142 | (if there isn't a empty value in the enum) | ||
| 8143 | */ | ||
| 8144 | |||
| 8145 | 21579774 | type_conversion_status Field_enum::store(const char *from, size_t length, | |
| 8146 | const CHARSET_INFO *cs) { | ||
| 8147 |
4/6✓ Branch 0 taken 21579774 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21341360 times.
✓ Branch 3 taken 238414 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 21341360 times.
|
21579774 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 8148 | 21579774 | int err = 0; | |
| 8149 | 21579774 | type_conversion_status ret = TYPE_OK; | |
| 8150 | char buff[STRING_BUFFER_USUAL_SIZE]; | ||
| 8151 | 21579774 | String tmpstr(buff, sizeof(buff), &my_charset_bin); | |
| 8152 | |||
| 8153 | /* Convert character set if necessary */ | ||
| 8154 |
3/4✓ Branch 0 taken 21579774 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 594843 times.
✓ Branch 3 taken 20984931 times.
|
21579774 | if (String::needs_conversion_on_storage(length, cs, field_charset)) { |
| 8155 | uint dummy_errors; | ||
| 8156 |
1/2✓ Branch 0 taken 594843 times.
✗ Branch 1 not taken.
|
594843 | tmpstr.copy(from, length, cs, field_charset, &dummy_errors); |
| 8157 | 594843 | from = tmpstr.ptr(); | |
| 8158 | 594843 | length = tmpstr.length(); | |
| 8159 | } | ||
| 8160 | |||
| 8161 | /* Remove end space */ | ||
| 8162 |
1/2✓ Branch 0 taken 21579774 times.
✗ Branch 1 not taken.
|
21579774 | length = field_charset->cset->lengthsp(field_charset, from, length); |
| 8163 |
1/2✓ Branch 0 taken 21579774 times.
✗ Branch 1 not taken.
|
21579774 | uint tmp = find_type2(typelib, from, length, field_charset); |
| 8164 |
2/2✓ Branch 0 taken 429192 times.
✓ Branch 1 taken 21150582 times.
|
21579774 | if (!tmp) { |
| 8165 |
2/2✓ Branch 0 taken 429109 times.
✓ Branch 1 taken 83 times.
|
429192 | if (length < 6) // Can't be more than 99999 enums |
| 8166 | { | ||
| 8167 | /* This is for reading numbers with LOAD DATA INFILE */ | ||
| 8168 | const char *end; | ||
| 8169 |
1/2✓ Branch 0 taken 429109 times.
✗ Branch 1 not taken.
|
429109 | tmp = (uint)my_strntoul(cs, from, length, 10, &end, &err); |
| 8170 |
6/6✓ Branch 0 taken 429049 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 429043 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 429040 times.
|
429109 | if (err || end != from + length || tmp > typelib->count) { |
| 8171 | 69 | tmp = 0; | |
| 8172 |
1/2✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
|
69 | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); |
| 8173 | 69 | ret = TYPE_WARN_TRUNCATED; | |
| 8174 | } | ||
| 8175 |
3/4✓ Branch 0 taken 429109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 428890 times.
✓ Branch 3 taken 219 times.
|
429109 | if (!current_thd->check_for_truncated_fields) ret = TYPE_OK; |
| 8176 | } else | ||
| 8177 |
1/2✓ Branch 0 taken 83 times.
✗ Branch 1 not taken.
|
83 | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); |
| 8178 | } | ||
| 8179 |
1/2✓ Branch 0 taken 21579774 times.
✗ Branch 1 not taken.
|
21579774 | store_type((ulonglong)tmp); |
| 8180 | 21579774 | return ret; | |
| 8181 | 21579774 | } | |
| 8182 | |||
| 8183 | 130 | type_conversion_status Field_enum::store(double nr) { | |
| 8184 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 129 times.
|
130 | if (nr < LLONG_MIN) |
| 8185 | 1 | return Field_enum::store(static_cast<longlong>(LLONG_MIN), false); | |
| 8186 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 128 times.
|
129 | if (nr > LLONG_MAX_DOUBLE) |
| 8187 | 1 | return Field_enum::store(static_cast<longlong>(LLONG_MAX), false); | |
| 8188 | 128 | return Field_enum::store(static_cast<longlong>(nr), false); | |
| 8189 | } | ||
| 8190 | |||
| 8191 | 35648268 | type_conversion_status Field_enum::store(longlong nr, bool) { | |
| 8192 |
4/6✓ Branch 0 taken 35648268 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35346590 times.
✓ Branch 3 taken 301678 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 35346593 times.
|
35648268 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 8193 | 35648271 | type_conversion_status error = TYPE_OK; | |
| 8194 |
4/4✓ Branch 0 taken 35648262 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 35648245 times.
|
35648271 | if ((ulonglong)nr > typelib->count || nr == 0) { |
| 8195 | 27 | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); | |
| 8196 |
6/6✓ Branch 0 taken 17 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 25 times.
✓ Branch 5 taken 2 times.
|
27 | if (nr != 0 || current_thd->check_for_truncated_fields) { |
| 8197 | 25 | nr = 0; | |
| 8198 | 25 | error = TYPE_WARN_TRUNCATED; | |
| 8199 | } | ||
| 8200 | } | ||
| 8201 | 35648272 | store_type((ulonglong)(uint)nr); | |
| 8202 | 35648273 | return error; | |
| 8203 | } | ||
| 8204 | |||
| 8205 | 1427 | double Field_enum::val_real() const { return (double)Field_enum::val_int(); } | |
| 8206 | |||
| 8207 | 2 | my_decimal *Field_enum::val_decimal(my_decimal *decimal_value) const { | |
| 8208 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 8209 | 2 | int2my_decimal(E_DEC_FATAL_ERROR, val_int(), false, decimal_value); | |
| 8210 | 2 | return decimal_value; | |
| 8211 | } | ||
| 8212 | |||
| 8213 | // Utility function used by ::val_int() and ::cmp() | ||
| 8214 | 359543528 | static longlong enum_val_int(const uchar *ptr, uint packlength, | |
| 8215 | bool low_byte_first) { | ||
| 8216 |
5/6✓ Branch 0 taken 356055402 times.
✓ Branch 1 taken 44924 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5000 times.
✓ Branch 4 taken 3438200 times.
✓ Branch 5 taken 2 times.
|
359543528 | switch (packlength) { |
| 8217 | 356055402 | case 1: | |
| 8218 | 356055402 | return ptr[0]; | |
| 8219 | 44924 | case 2: { | |
| 8220 |
1/2✓ Branch 0 taken 44924 times.
✗ Branch 1 not taken.
|
44924 | if (low_byte_first) |
| 8221 | 44924 | return uint2korr(ptr); | |
| 8222 | else | ||
| 8223 | ✗ | return ushortget(ptr); | |
| 8224 | } | ||
| 8225 | ✗ | case 3: | |
| 8226 | ✗ | return uint3korr(ptr); | |
| 8227 | 5000 | case 4: { | |
| 8228 |
1/2✓ Branch 0 taken 5000 times.
✗ Branch 1 not taken.
|
5000 | if (low_byte_first) |
| 8229 | 5000 | return uint4korr(ptr); | |
| 8230 | else | ||
| 8231 | ✗ | return ulongget(ptr); | |
| 8232 | } | ||
| 8233 | 3438200 | case 8: { | |
| 8234 |
1/2✓ Branch 0 taken 3438200 times.
✗ Branch 1 not taken.
|
3438200 | if (low_byte_first) |
| 8235 | 3438200 | return sint8korr(ptr); | |
| 8236 | else | ||
| 8237 | ✗ | return longlongget(ptr); | |
| 8238 | } | ||
| 8239 | } | ||
| 8240 | 2 | return 0; // impossible | |
| 8241 | } | ||
| 8242 | |||
| 8243 | 359413877 | longlong Field_enum::val_int() const { | |
| 8244 |
4/6✓ Branch 0 taken 359413880 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 359164804 times.
✓ Branch 3 taken 249076 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 359164805 times.
|
359413877 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 8245 | 359413878 | return enum_val_int(ptr, packlength, table->s->db_low_byte_first); | |
| 8246 | } | ||
| 8247 | |||
| 8248 | /** | ||
| 8249 | Save the field metadata for enum fields. | ||
| 8250 | |||
| 8251 | Saves the real type in the first byte and the pack length in the | ||
| 8252 | second byte of the field metadata array at index of *metadata_ptr and | ||
| 8253 | *(metadata_ptr + 1). | ||
| 8254 | |||
| 8255 | @param metadata_ptr First byte of field metadata | ||
| 8256 | |||
| 8257 | @returns number of bytes written to metadata_ptr | ||
| 8258 | */ | ||
| 8259 | 31793 | int Field_enum::do_save_field_metadata(uchar *metadata_ptr) const { | |
| 8260 | 31793 | *metadata_ptr = real_type(); | |
| 8261 | 31793 | *(metadata_ptr + 1) = pack_length(); | |
| 8262 | 31793 | return 2; | |
| 8263 | } | ||
| 8264 | |||
| 8265 | 137853732 | String *Field_enum::val_str(String *, String *val_ptr) const { | |
| 8266 | 137853732 | uint tmp = (uint)Field_enum::val_int(); | |
| 8267 |
4/4✓ Branch 0 taken 137775999 times.
✓ Branch 1 taken 77733 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 137775996 times.
|
137853732 | if (!tmp || tmp > typelib->count) |
| 8268 | 77736 | val_ptr->set("", 0, field_charset); | |
| 8269 | else | ||
| 8270 | 137775996 | val_ptr->set(typelib->type_names[tmp - 1], typelib->type_lengths[tmp - 1], | |
| 8271 | 137775996 | field_charset); | |
| 8272 | 137853732 | return val_ptr; | |
| 8273 | } | ||
| 8274 | |||
| 8275 | 64824 | int Field_enum::cmp(const uchar *a_ptr, const uchar *b_ptr) const { | |
| 8276 | const longlong a = | ||
| 8277 | 64824 | enum_val_int(a_ptr, packlength, table->s->db_low_byte_first); | |
| 8278 | const longlong b = | ||
| 8279 | 64824 | enum_val_int(b_ptr, packlength, table->s->db_low_byte_first); | |
| 8280 |
4/4✓ Branch 0 taken 64528 times.
✓ Branch 1 taken 296 times.
✓ Branch 2 taken 391 times.
✓ Branch 3 taken 64137 times.
|
64824 | return (a < b) ? -1 : (a > b) ? 1 : 0; |
| 8281 | } | ||
| 8282 | |||
| 8283 | 1112 | size_t Field_enum::make_sort_key(uchar *to, size_t length) const { | |
| 8284 | #ifdef WORDS_BIGENDIAN | ||
| 8285 | if (!table->s->db_low_byte_first) | ||
| 8286 | copy_integer<true>(to, length, ptr, packlength, true); | ||
| 8287 | else | ||
| 8288 | #endif | ||
| 8289 | 1112 | copy_integer<false>(to, length, ptr, packlength, true); | |
| 8290 | 1112 | return length; | |
| 8291 | } | ||
| 8292 | |||
| 8293 | 1495654 | void Field_enum::sql_type(String &res) const { | |
| 8294 | char buffer[255]; | ||
| 8295 | 1495654 | String enum_item(buffer, sizeof(buffer), res.charset()); | |
| 8296 | |||
| 8297 | 1495654 | res.length(0); | |
| 8298 |
1/2✓ Branch 0 taken 1495654 times.
✗ Branch 1 not taken.
|
1495654 | res.append(STRING_WITH_LEN("enum(")); |
| 8299 | |||
| 8300 | 1495654 | bool flag = false; | |
| 8301 | 1495654 | uint *len = typelib->type_lengths; | |
| 8302 |
2/2✓ Branch 0 taken 5017012 times.
✓ Branch 1 taken 1495654 times.
|
6512666 | for (const char **pos = typelib->type_names; *pos; pos++, len++) { |
| 8303 | uint dummy_errors; | ||
| 8304 |
3/4✓ Branch 0 taken 3521358 times.
✓ Branch 1 taken 1495654 times.
✓ Branch 2 taken 3521358 times.
✗ Branch 3 not taken.
|
5017012 | if (flag) res.append(','); |
| 8305 | /* convert to res.charset() == utf8, then quote */ | ||
| 8306 |
2/4✓ Branch 0 taken 5017012 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5017012 times.
✗ Branch 3 not taken.
|
5017012 | enum_item.copy(*pos, *len, charset(), res.charset(), &dummy_errors); |
| 8307 | |||
| 8308 | 5017012 | const CHARSET_INFO *cs = res.charset(); | |
| 8309 | 5017012 | int well_formed_error = 42; | |
| 8310 | #ifndef NDEBUG | ||
| 8311 | size_t wl = | ||
| 8312 | #endif | ||
| 8313 |
1/2✓ Branch 0 taken 5017012 times.
✗ Branch 1 not taken.
|
10034024 | cs->cset->well_formed_len(cs, enum_item.ptr(), |
| 8314 | 5017012 | enum_item.ptr() + enum_item.length(), | |
| 8315 | enum_item.length(), &well_formed_error); | ||
| 8316 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5017012 times.
|
5017012 | assert(wl <= enum_item.length()); |
| 8317 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5017004 times.
|
5017012 | if (well_formed_error) { |
| 8318 | // Append the hex literal instead | ||
| 8319 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | res.append("x'"); |
| 8320 | char b[6]; | ||
| 8321 | 8 | const char *eip = enum_item.ptr(); | |
| 8322 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 8 times.
|
30 | for (size_t i = 0; i < enum_item.length(); ++i) { |
| 8323 | 22 | unsigned char v = static_cast<unsigned char>(eip[i]); | |
| 8324 | 22 | snprintf(b, sizeof(b), "%x", v); | |
| 8325 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | res.append(b); |
| 8326 | } | ||
| 8327 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | res.append("'"); |
| 8328 | } else { | ||
| 8329 |
1/2✓ Branch 0 taken 5017004 times.
✗ Branch 1 not taken.
|
5017004 | append_unescaped(&res, enum_item.ptr(), enum_item.length()); |
| 8330 | } | ||
| 8331 | 5017012 | flag = true; | |
| 8332 | } | ||
| 8333 |
1/2✓ Branch 0 taken 1495654 times.
✗ Branch 1 not taken.
|
1495654 | res.append(')'); |
| 8334 | 1495654 | } | |
| 8335 | |||
| 8336 | 403348 | Field *Field_enum::new_field(MEM_ROOT *root, TABLE *new_table) const { | |
| 8337 | 403348 | Field_enum *res = down_cast<Field_enum *>(Field::new_field(root, new_table)); | |
| 8338 |
1/2✓ Branch 0 taken 403348 times.
✗ Branch 1 not taken.
|
403348 | if (res) res->typelib = copy_typelib(root, typelib); |
| 8339 | 403348 | return res; | |
| 8340 | } | ||
| 8341 | |||
| 8342 | /* | ||
| 8343 | set type. | ||
| 8344 | This is a string which can have a collection of different values. | ||
| 8345 | Each string value is separated with a ','. | ||
| 8346 | For example "One,two,five" | ||
| 8347 | If one uses this string in a number context one gets the bits as a longlong | ||
| 8348 | number. | ||
| 8349 | */ | ||
| 8350 | |||
| 8351 | 1672579 | type_conversion_status Field_set::store(const char *from, size_t length, | |
| 8352 | const CHARSET_INFO *cs) { | ||
| 8353 |
4/6✓ Branch 0 taken 1672579 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1661925 times.
✓ Branch 3 taken 10654 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1661925 times.
|
1672579 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 8354 | 1672579 | bool got_warning = false; | |
| 8355 | 1672579 | int err = 0; | |
| 8356 | 1672579 | type_conversion_status ret = TYPE_OK; | |
| 8357 | const char *not_used; | ||
| 8358 | uint not_used2; | ||
| 8359 | char buff[STRING_BUFFER_USUAL_SIZE]; | ||
| 8360 | 1672579 | String tmpstr(buff, sizeof(buff), &my_charset_bin); | |
| 8361 | |||
| 8362 | /* Convert character set if necessary */ | ||
| 8363 |
3/4✓ Branch 0 taken 1672579 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1366 times.
✓ Branch 3 taken 1671213 times.
|
1672579 | if (String::needs_conversion_on_storage(length, cs, field_charset)) { |
| 8364 | uint dummy_errors; | ||
| 8365 |
1/2✓ Branch 0 taken 1366 times.
✗ Branch 1 not taken.
|
1366 | tmpstr.copy(from, length, cs, field_charset, &dummy_errors); |
| 8366 | 1366 | from = tmpstr.ptr(); | |
| 8367 | 1366 | length = tmpstr.length(); | |
| 8368 | } | ||
| 8369 |
1/2✓ Branch 0 taken 1672579 times.
✗ Branch 1 not taken.
|
1672579 | ulonglong tmp = find_set(typelib, from, length, field_charset, ¬_used, |
| 8370 | ¬_used2, &got_warning); | ||
| 8371 |
6/6✓ Branch 0 taken 26240 times.
✓ Branch 1 taken 1646339 times.
✓ Branch 2 taken 255 times.
✓ Branch 3 taken 25985 times.
✓ Branch 4 taken 233 times.
✓ Branch 5 taken 22 times.
|
1672579 | if (!tmp && length && length < 22) { |
| 8372 | /* This is for reading numbers with LOAD DATA INFILE */ | ||
| 8373 | const char *end; | ||
| 8374 |
1/2✓ Branch 0 taken 233 times.
✗ Branch 1 not taken.
|
233 | tmp = my_strntoull(cs, from, length, 10, &end, &err); |
| 8375 |
4/4✓ Branch 0 taken 173 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 166 times.
✓ Branch 3 taken 7 times.
|
233 | if (err || end != from + length || |
| 8376 |
4/4✓ Branch 0 taken 165 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 153 times.
|
166 | (typelib->count < 64 && tmp >= (1ULL << typelib->count))) { |
| 8377 | 79 | tmp = 0; | |
| 8378 |
1/2✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
|
79 | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); |
| 8379 | 79 | ret = TYPE_WARN_TRUNCATED; | |
| 8380 | } | ||
| 8381 |
2/2✓ Branch 0 taken 45 times.
✓ Branch 1 taken 1672301 times.
|
1672579 | } else if (got_warning) |
| 8382 |
1/2✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
|
45 | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); |
| 8383 |
1/2✓ Branch 0 taken 1672579 times.
✗ Branch 1 not taken.
|
1672579 | store_type(tmp); |
| 8384 | 1672579 | return ret; | |
| 8385 | 1672579 | } | |
| 8386 | |||
| 8387 | 75661 | type_conversion_status Field_set::store(longlong nr, bool) { | |
| 8388 |
4/6✓ Branch 0 taken 75661 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 75657 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 75657 times.
|
75661 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 8389 | 75661 | type_conversion_status error = TYPE_OK; | |
| 8390 | ulonglong max_nr; | ||
| 8391 | |||
| 8392 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 75659 times.
|
75661 | if (sizeof(ulonglong) * 8 <= typelib->count) |
| 8393 | 2 | max_nr = ULLONG_MAX; | |
| 8394 | else | ||
| 8395 | 75659 | max_nr = (1ULL << typelib->count) - 1; | |
| 8396 | |||
| 8397 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 75650 times.
|
75661 | if ((ulonglong)nr > max_nr) { |
| 8398 | 11 | nr &= max_nr; | |
| 8399 | 11 | set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1); | |
| 8400 | 11 | error = TYPE_WARN_TRUNCATED; | |
| 8401 | } | ||
| 8402 | 75661 | store_type((ulonglong)nr); | |
| 8403 | 75661 | return error; | |
| 8404 | } | ||
| 8405 | |||
| 8406 | 3410965 | String *Field_set::val_str(String *val_buffer, String *) const { | |
| 8407 | 3410965 | ulonglong tmp = (ulonglong)Field_enum::val_int(); | |
| 8408 | 3410965 | uint bitnr = 0; | |
| 8409 | |||
| 8410 | /* | ||
| 8411 | Some callers expect *val_buffer to contain the result, | ||
| 8412 | so we assign to it, rather than doing 'return &empty_set_string. | ||
| 8413 | */ | ||
| 8414 | 3410965 | *val_buffer = empty_set_string; | |
| 8415 |
2/2✓ Branch 0 taken 103960 times.
✓ Branch 1 taken 3307005 times.
|
3410965 | if (tmp == 0) { |
| 8416 | 103960 | return val_buffer; | |
| 8417 | } | ||
| 8418 | |||
| 8419 | 3307005 | val_buffer->set_charset(field_charset); | |
| 8420 | 3307005 | val_buffer->length(0); | |
| 8421 | |||
| 8422 |
4/4✓ Branch 0 taken 101745390 times.
✓ Branch 1 taken 3307001 times.
✓ Branch 2 taken 101745386 times.
✓ Branch 3 taken 4 times.
|
105052391 | while (tmp && bitnr < typelib->count) { |
| 8423 |
2/2✓ Branch 0 taken 19709004 times.
✓ Branch 1 taken 82036382 times.
|
101745386 | if (tmp & 1) { |
| 8424 |
2/2✓ Branch 0 taken 16402003 times.
✓ Branch 1 taken 3307001 times.
|
19709004 | if (val_buffer->length()) |
| 8425 |
1/2✓ Branch 0 taken 16402003 times.
✗ Branch 1 not taken.
|
16402003 | val_buffer->append(&field_separator, 1, &my_charset_latin1); |
| 8426 | 19709004 | String str(typelib->type_names[bitnr], typelib->type_lengths[bitnr], | |
| 8427 | 19709004 | field_charset); | |
| 8428 |
1/2✓ Branch 0 taken 19709004 times.
✗ Branch 1 not taken.
|
19709004 | val_buffer->append(str); |
| 8429 | 19709004 | } | |
| 8430 | 101745386 | tmp >>= 1; | |
| 8431 | 101745386 | bitnr++; | |
| 8432 | } | ||
| 8433 | 3307005 | return val_buffer; | |
| 8434 | } | ||
| 8435 | |||
| 8436 | 111326 | void Field_set::sql_type(String &res) const { | |
| 8437 | char buffer[255]; | ||
| 8438 | 111326 | String set_item(buffer, sizeof(buffer), res.charset()); | |
| 8439 | |||
| 8440 | 111326 | res.length(0); | |
| 8441 |
1/2✓ Branch 0 taken 111326 times.
✗ Branch 1 not taken.
|
111326 | res.append(STRING_WITH_LEN("set(")); |
| 8442 | |||
| 8443 | 111326 | bool flag = false; | |
| 8444 | 111326 | uint *len = typelib->type_lengths; | |
| 8445 |
2/2✓ Branch 0 taken 1645208 times.
✓ Branch 1 taken 111326 times.
|
1756534 | for (const char **pos = typelib->type_names; *pos; pos++, len++) { |
| 8446 | uint dummy_errors; | ||
| 8447 |
3/4✓ Branch 0 taken 1533882 times.
✓ Branch 1 taken 111326 times.
✓ Branch 2 taken 1533882 times.
✗ Branch 3 not taken.
|
1645208 | if (flag) res.append(','); |
| 8448 | /* convert to res.charset() == utf8, then quote */ | ||
| 8449 |
1/2✓ Branch 0 taken 1645208 times.
✗ Branch 1 not taken.
|
1645208 | set_item.copy(*pos, *len, charset(), res.charset(), &dummy_errors); |
| 8450 |
1/2✓ Branch 0 taken 1645208 times.
✗ Branch 1 not taken.
|
1645208 | append_unescaped(&res, set_item.ptr(), set_item.length()); |
| 8451 | 1645208 | flag = true; | |
| 8452 | } | ||
| 8453 |
1/2✓ Branch 0 taken 111326 times.
✗ Branch 1 not taken.
|
111326 | res.append(')'); |
| 8454 | 111326 | } | |
| 8455 | |||
| 8456 | /** | ||
| 8457 | @retval | ||
| 8458 | true if the fields are equally defined | ||
| 8459 | @retval | ||
| 8460 | false if the fields are unequally defined | ||
| 8461 | */ | ||
| 8462 | |||
| 8463 | 7249503 | bool Field::eq_def(const Field *field) const { | |
| 8464 |
6/6✓ Branch 0 taken 7216502 times.
✓ Branch 1 taken 33028 times.
✓ Branch 2 taken 7192231 times.
✓ Branch 3 taken 24254 times.
✓ Branch 4 taken 57835 times.
✓ Branch 5 taken 7191677 times.
|
14441733 | if (real_type() != field->real_type() || charset() != field->charset() || |
| 8465 |
2/2✓ Branch 0 taken 553 times.
✓ Branch 1 taken 7191677 times.
|
7192231 | pack_length() != field->pack_length()) |
| 8466 | 57835 | return false; | |
| 8467 | 7191677 | return true; | |
| 8468 | } | ||
| 8469 | |||
| 8470 | /** | ||
| 8471 | Compare the first t1::count type names. | ||
| 8472 | |||
| 8473 | @return true if the type names of t1 match those of t2. false otherwise. | ||
| 8474 | */ | ||
| 8475 | |||
| 8476 | 608654 | static bool compare_type_names(const CHARSET_INFO *charset, TYPELIB *t1, | |
| 8477 | TYPELIB *t2) { | ||
| 8478 |
2/2✓ Branch 0 taken 3469850 times.
✓ Branch 1 taken 608645 times.
|
4078495 | for (uint i = 0; i < t1->count; i++) |
| 8479 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3469841 times.
|
3469850 | if (my_strnncoll(charset, (const uchar *)t1->type_names[i], |
| 8480 | t1->type_lengths[i], (const uchar *)t2->type_names[i], | ||
| 8481 | t2->type_lengths[i])) | ||
| 8482 | 9 | return false; | |
| 8483 | 608645 | return true; | |
| 8484 | } | ||
| 8485 | |||
| 8486 | /** | ||
| 8487 | @return | ||
| 8488 | returns 1 if the fields are equally defined | ||
| 8489 | */ | ||
| 8490 | |||
| 8491 | 397532 | bool Field_enum::eq_def(const Field *field) const { | |
| 8492 | TYPELIB *values; | ||
| 8493 | |||
| 8494 |
2/2✓ Branch 0 taken 7130 times.
✓ Branch 1 taken 390402 times.
|
397532 | if (!Field::eq_def(field)) return false; |
| 8495 | |||
| 8496 | 390402 | values = down_cast<const Field_enum *>(field)->typelib; | |
| 8497 | |||
| 8498 | /* Definition must be strictly equal. */ | ||
| 8499 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 390382 times.
|
390402 | if (typelib->count != values->count) return false; |
| 8500 | |||
| 8501 | 390382 | return compare_type_names(field_charset, typelib, values); | |
| 8502 | } | ||
| 8503 | |||
| 8504 | /** | ||
| 8505 | Check whether two fields can be considered 'equal' for table | ||
| 8506 | alteration purposes. Fields are equal if they retain the same | ||
| 8507 | pack length and if new members are added to the end of the list. | ||
| 8508 | |||
| 8509 | @return IS_EQUAL_YES if fields are compatible. | ||
| 8510 | IS_EQUAL_NO otherwise. | ||
| 8511 | */ | ||
| 8512 | |||
| 8513 | 218305 | uint Field_enum::is_equal(const Create_field *new_field) const { | |
| 8514 |
1/2✓ Branch 0 taken 218305 times.
✗ Branch 1 not taken.
|
218305 | DBUG_TRACE; |
| 8515 | /* | ||
| 8516 | The fields are compatible if they have the same flags, | ||
| 8517 | type, charset and have the same underlying length. | ||
| 8518 | */ | ||
| 8519 |
3/4✓ Branch 0 taken 218305 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 218290 times.
|
218305 | if (sql_type_prevents_inplace(*this, *new_field)) { |
| 8520 |
3/8✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
15 | DBUG_PRINT("inplace", ("-> IS_EQUAL_NO")); |
| 8521 | 15 | return IS_EQUAL_NO; | |
| 8522 | } | ||
| 8523 | 218290 | TYPELIB *new_typelib = new_field->interval; | |
| 8524 | |||
| 8525 | /* | ||
| 8526 | Changing the definition of an ENUM or SET column by adding a new | ||
| 8527 | enumeration or set members to the end of the list of valid member | ||
| 8528 | values only alters table metadata and not table data. | ||
| 8529 | */ | ||
| 8530 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 218272 times.
|
218290 | if (typelib->count > new_typelib->count) { |
| 8531 |
3/8✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
18 | DBUG_PRINT("inplace", ("(typelib->count > new_typelib->count) -> " |
| 8532 | "IS_EQUAL_NO")); | ||
| 8533 | 18 | return IS_EQUAL_NO; | |
| 8534 | } | ||
| 8535 | |||
| 8536 | /* Check whether there are modification before the end. Since we | ||
| 8537 | know that the charset change (if there is one) is | ||
| 8538 | inplace-compatible, it is safe to perform the comparison using the | ||
| 8539 | new charset. | ||
| 8540 | */ | ||
| 8541 |
3/4✓ Branch 0 taken 218272 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 218263 times.
|
218272 | if (!compare_type_names(new_field->charset, typelib, new_typelib)) { |
| 8542 |
3/8✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
9 | DBUG_PRINT("inplace", ("!compare_type_names() -> IS_EQUAL_NO")); |
| 8543 | 9 | return IS_EQUAL_NO; | |
| 8544 | } | ||
| 8545 | |||
| 8546 |
3/12✓ Branch 0 taken 218263 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 218263 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 218263 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
218263 | DBUG_PRINT("inplace", |
| 8547 | ("Field_enum::is_equal() -> %s", | ||
| 8548 | (new_field->pack_length() == pack_length() ? "IS_EQUAL_YES" | ||
| 8549 | : "IS_EQUAL_NO"))); | ||
| 8550 | |||
| 8551 | // Can't return IS_EQUAL_PACK_LENGTH here as using inplace leads to | ||
| 8552 | // assert when trying to insert set elements that use bits outside | ||
| 8553 | // the original length: | ||
| 8554 | // Assertion failure: rem0rec.cc:408:len <= fixed_len thread 140301224261376 | ||
| 8555 |
3/4✓ Branch 0 taken 218263 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 218255 times.
✓ Branch 3 taken 8 times.
|
218263 | return (new_field->pack_length() == pack_length() ? IS_EQUAL_YES |
| 8556 | 218263 | : IS_EQUAL_NO); | |
| 8557 | 218305 | } | |
| 8558 | |||
| 8559 | 2659533 | uchar *Field_enum::pack(uchar *to, const uchar *from, size_t max_length) const { | |
| 8560 |
1/2✓ Branch 0 taken 2659533 times.
✗ Branch 1 not taken.
|
2659533 | DBUG_TRACE; |
| 8561 |
5/8✓ Branch 0 taken 2659533 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2659533 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 417 times.
✓ Branch 5 taken 2659116 times.
✓ Branch 6 taken 417 times.
✗ Branch 7 not taken.
|
2659533 | DBUG_PRINT("debug", ("packlength: %d", packlength)); |
| 8562 |
1/2✓ Branch 0 taken 2659533 times.
✗ Branch 1 not taken.
|
2659533 | DBUG_DUMP("from", from, packlength); |
| 8563 | |||
| 8564 |
4/6✓ Branch 0 taken 2651372 times.
✓ Branch 1 taken 7757 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 84 times.
✓ Branch 4 taken 320 times.
✗ Branch 5 not taken.
|
2659533 | switch (packlength) { |
| 8565 | 2651372 | case 1: | |
| 8566 |
1/2✓ Branch 0 taken 2651372 times.
✗ Branch 1 not taken.
|
2651372 | if (max_length > 0) *to = *from; |
| 8567 | 2651372 | return to + 1; | |
| 8568 | 7757 | case 2: | |
| 8569 |
1/2✓ Branch 0 taken 7757 times.
✗ Branch 1 not taken.
|
7757 | return pack_int16(to, from, max_length); |
| 8570 | ✗ | case 3: | |
| 8571 | ✗ | return pack_int24(to, from, max_length); | |
| 8572 | 84 | case 4: | |
| 8573 |
1/2✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
|
84 | return pack_int32(to, from, max_length); |
| 8574 | 320 | case 8: | |
| 8575 |
1/2✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
|
320 | return pack_int64(to, from, max_length); |
| 8576 | ✗ | default: | |
| 8577 | ✗ | assert(0); | |
| 8578 | } | ||
| 8579 | MY_ASSERT_UNREACHABLE(); | ||
| 8580 | return nullptr; | ||
| 8581 | 2659533 | } | |
| 8582 | |||
| 8583 | 2677005 | const uchar *Field_enum::unpack(uchar *to, const uchar *from, uint) { | |
| 8584 |
1/2✓ Branch 0 taken 2677005 times.
✗ Branch 1 not taken.
|
2677005 | DBUG_TRACE; |
| 8585 |
3/8✓ Branch 0 taken 2677005 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2677005 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2677005 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
2677005 | DBUG_PRINT("debug", ("packlength: %d", packlength)); |
| 8586 |
1/2✓ Branch 0 taken 2677005 times.
✗ Branch 1 not taken.
|
2677005 | DBUG_DUMP("from", from, packlength); |
| 8587 | |||
| 8588 |
3/6✓ Branch 0 taken 2673533 times.
✓ Branch 1 taken 3272 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 200 times.
✗ Branch 5 not taken.
|
2677005 | switch (packlength) { |
| 8589 | 2673533 | case 1: | |
| 8590 | 2673533 | *to = *from; | |
| 8591 | 2673533 | return from + 1; | |
| 8592 | |||
| 8593 | 3272 | case 2: | |
| 8594 |
1/2✓ Branch 0 taken 3272 times.
✗ Branch 1 not taken.
|
3272 | return unpack_int16(to, from); |
| 8595 | ✗ | case 3: | |
| 8596 | ✗ | return unpack_int24(to, from); | |
| 8597 | ✗ | case 4: | |
| 8598 | ✗ | return unpack_int32(to, from); | |
| 8599 | 200 | case 8: | |
| 8600 |
1/2✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
|
200 | return unpack_int64(to, from); |
| 8601 | ✗ | default: | |
| 8602 | ✗ | assert(0); | |
| 8603 | } | ||
| 8604 | MY_ASSERT_UNREACHABLE(); | ||
| 8605 | return nullptr; | ||
| 8606 | 2677005 | } | |
| 8607 | |||
| 8608 | /** | ||
| 8609 | @return | ||
| 8610 | returns true if the fields are equally defined | ||
| 8611 | */ | ||
| 8612 | 4510707 | bool Field_num::eq_def(const Field *field) const { | |
| 8613 |
2/2✓ Branch 0 taken 4941 times.
✓ Branch 1 taken 4505785 times.
|
4510707 | if (!Field::eq_def(field)) return false; |
| 8614 | 4505785 | const Field_num *from_num = down_cast<const Field_num *>(field); | |
| 8615 | |||
| 8616 | 4505773 | if (is_unsigned() != from_num->is_unsigned() || | |
| 8617 |
8/12✓ Branch 0 taken 4504715 times.
✓ Branch 1 taken 1073 times.
✓ Branch 2 taken 4630 times.
✓ Branch 3 taken 4500085 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4630 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4504714 times.
✓ Branch 10 taken 1074 times.
✓ Branch 11 taken 4504714 times.
|
4505788 | (zerofill && !from_num->zerofill && !zero_pack()) || dec != from_num->dec) |
| 8618 | 1074 | return false; | |
| 8619 | 4504714 | return true; | |
| 8620 | } | ||
| 8621 | |||
| 8622 | /** | ||
| 8623 | Check whether two numeric fields can be considered 'equal' for table | ||
| 8624 | alteration purposes. Fields are equal if they are of the same type | ||
| 8625 | and retain the same pack length. | ||
| 8626 | */ | ||
| 8627 | |||
| 8628 | 201701 | uint Field_num::is_equal(const Create_field *new_field) const { | |
| 8629 |
2/2✓ Branch 0 taken 200802 times.
✓ Branch 1 taken 164 times.
|
402667 | return (new_field->sql_type == real_type()) && |
| 8630 | 200966 | (Overlaps(new_field->flags, UNSIGNED_FLAG) == | |
| 8631 |
2/2✓ Branch 0 taken 200698 times.
✓ Branch 1 taken 104 times.
|
401768 | is_flag_set(UNSIGNED_FLAG)) && |
| 8632 | 200802 | (Overlaps(new_field->flags, AUTO_INCREMENT_FLAG) == | |
| 8633 |
2/2✓ Branch 0 taken 200966 times.
✓ Branch 1 taken 735 times.
|
603469 | is_flag_set(AUTO_INCREMENT_FLAG)) && |
| 8634 |
1/2✓ Branch 0 taken 200698 times.
✗ Branch 1 not taken.
|
402399 | (new_field->pack_length() == pack_length()); |
| 8635 | } | ||
| 8636 | |||
| 8637 | /* | ||
| 8638 | Bit field. | ||
| 8639 | |||
| 8640 | We store the first 0 - 6 uneven bits among the null bits | ||
| 8641 | at the start of the record. The rest bytes are stored in | ||
| 8642 | the record itself. | ||
| 8643 | |||
| 8644 | For example: | ||
| 8645 | |||
| 8646 | CREATE TABLE t1 (a int, b bit(17), c bit(21) not null, d bit(8)); | ||
| 8647 | We would store data as follows in the record: | ||
| 8648 | |||
| 8649 | Byte Bit | ||
| 8650 | 1 7 - reserve for delete | ||
| 8651 | 6 - null bit for 'a' | ||
| 8652 | 5 - null bit for 'b' | ||
| 8653 | 4 - first (high) bit of 'b' | ||
| 8654 | 3 - first (high) bit of 'c' | ||
| 8655 | 2 - second bit of 'c' | ||
| 8656 | 1 - third bit of 'c' | ||
| 8657 | 0 - forth bit of 'c' | ||
| 8658 | 2 7 - firth bit of 'c' | ||
| 8659 | 6 - null bit for 'd' | ||
| 8660 | 3 - 6 four bytes for 'a' | ||
| 8661 | 7 - 8 two bytes for 'b' | ||
| 8662 | 9 - 10 two bytes for 'c' | ||
| 8663 | 11 one byte for 'd' | ||
| 8664 | */ | ||
| 8665 | |||
| 8666 | 14716 | Field_bit::Field_bit(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, | |
| 8667 | uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg, | ||
| 8668 | 14716 | uchar auto_flags_arg, const char *field_name_arg) | |
| 8669 | : Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg, | ||
| 8670 | field_name_arg), | ||
| 8671 | 14716 | bit_ptr(bit_ptr_arg), | |
| 8672 | 14716 | bit_ofs(bit_ofs_arg), | |
| 8673 | 14716 | bit_len(len_arg & 7), | |
| 8674 | 14716 | bytes_in_rec(len_arg / 8) { | |
| 8675 |
1/2✓ Branch 0 taken 14716 times.
✗ Branch 1 not taken.
|
14716 | DBUG_TRACE; |
| 8676 |
3/8✓ Branch 0 taken 14716 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14716 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14716 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
14716 | DBUG_PRINT("enter", ("ptr_arg: %p, null_ptr_arg: %p, len_arg: %u, bit_len: " |
| 8677 | "%u, bytes_in_rec: %u", | ||
| 8678 | ptr_arg, null_ptr_arg, len_arg, bit_len, bytes_in_rec)); | ||
| 8679 | 14716 | set_flag(UNSIGNED_FLAG); | |
| 8680 | /* | ||
| 8681 | Ensure that Field::eq() can distinguish between two different bit fields. | ||
| 8682 | (two bit fields that are not null, may have same ptr and m_null_ptr) | ||
| 8683 | */ | ||
| 8684 |
2/2✓ Branch 0 taken 6556 times.
✓ Branch 1 taken 8160 times.
|
14716 | if (!null_ptr_arg) null_bit = bit_ofs_arg; |
| 8685 | 14716 | } | |
| 8686 | |||
| 8687 | 1229 | void Field_bit::hash(ulong *nr, ulong *nr2) const { | |
| 8688 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1224 times.
|
1229 | if (is_null()) { |
| 8689 | 5 | *nr ^= (*nr << 1) | 1; | |
| 8690 | } else { | ||
| 8691 | 1224 | const CHARSET_INFO *cs = &my_charset_bin; | |
| 8692 |
1/2✓ Branch 0 taken 1224 times.
✗ Branch 1 not taken.
|
1224 | longlong value = Field_bit::val_int(); |
| 8693 | uchar tmp[8]; | ||
| 8694 | 1224 | mi_int8store(tmp, value); | |
| 8695 | |||
| 8696 | 1224 | uint64 tmp1 = *nr; | |
| 8697 | 1224 | uint64 tmp2 = *nr2; | |
| 8698 |
1/2✓ Branch 0 taken 1224 times.
✗ Branch 1 not taken.
|
1224 | cs->coll->hash_sort(cs, tmp, 8, &tmp1, &tmp2); |
| 8699 | |||
| 8700 | // NOTE: This truncates to 32-bit on Windows, to keep on-disk stability. | ||
| 8701 | 1224 | *nr = static_cast<ulong>(tmp1); | |
| 8702 | 1224 | *nr2 = static_cast<ulong>(tmp2); | |
| 8703 | } | ||
| 8704 | 1229 | } | |
| 8705 | |||
| 8706 | 574 | Field *Field_bit::new_key_field(MEM_ROOT *root, TABLE *new_table, | |
| 8707 | uchar *new_ptr, uchar *new_null_ptr, | ||
| 8708 | uint new_null_bit) const { | ||
| 8709 | Field_bit *res; | ||
| 8710 |
1/2✓ Branch 0 taken 574 times.
✗ Branch 1 not taken.
|
574 | if ((res = (Field_bit *)Field::new_key_field(root, new_table, new_ptr, |
| 8711 | new_null_ptr, new_null_bit))) { | ||
| 8712 | /* Move bits normally stored in null_pointer to new_ptr */ | ||
| 8713 | 574 | res->bit_ptr = new_ptr; | |
| 8714 | 574 | res->bit_ofs = 0; | |
| 8715 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 570 times.
|
574 | if (bit_len) res->ptr++; // Store rest of data here |
| 8716 | } | ||
| 8717 | 574 | return res; | |
| 8718 | } | ||
| 8719 | |||
| 8720 | 477 | uint Field_bit::is_equal(const Create_field *new_field) const { | |
| 8721 |
1/2✓ Branch 0 taken 477 times.
✗ Branch 1 not taken.
|
954 | return (new_field->sql_type == real_type() && |
| 8722 |
2/2✓ Branch 0 taken 460 times.
✓ Branch 1 taken 17 times.
|
954 | new_field->max_display_width_in_bytes() == max_display_length()); |
| 8723 | } | ||
| 8724 | |||
| 8725 | 17618 | type_conversion_status Field_bit::reset() { | |
| 8726 | 17618 | memset(ptr, 0, bytes_in_rec); | |
| 8727 |
4/4✓ Branch 0 taken 3693 times.
✓ Branch 1 taken 13925 times.
✓ Branch 2 taken 1088 times.
✓ Branch 3 taken 2605 times.
|
17618 | if (bit_ptr && (bit_len > 0)) // reset odd bits among null bits |
| 8728 |
2/2✓ Branch 0 taken 157 times.
✓ Branch 1 taken 931 times.
|
1088 | clr_rec_bits(bit_ptr, bit_ofs, bit_len); |
| 8729 | 17618 | return TYPE_OK; | |
| 8730 | } | ||
| 8731 | |||
| 8732 | 730 | type_conversion_status Field_bit::store(const char *from, size_t length, | |
| 8733 | const CHARSET_INFO *) { | ||
| 8734 |
4/6✓ Branch 0 taken 730 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 720 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 720 times.
|
730 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 8735 | int delta; | ||
| 8736 | |||
| 8737 |
4/4✓ Branch 0 taken 5373 times.
✓ Branch 1 taken 155 times.
✓ Branch 2 taken 4798 times.
✓ Branch 3 taken 575 times.
|
5528 | for (; length && !*from; from++, length--) |
| 8738 | ; // skip left 0's | ||
| 8739 | 730 | delta = bytes_in_rec - static_cast<int>(length); | |
| 8740 | |||
| 8741 | /* | ||
| 8742 | *from should probably be treated like uint here see BUG#13727586 | ||
| 8743 | */ | ||
| 8744 |
5/6✓ Branch 0 taken 730 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 375 times.
✓ Branch 3 taken 355 times.
✓ Branch 4 taken 324 times.
✓ Branch 5 taken 51 times.
|
730 | if (delta < -1 || (delta == -1 && (uchar)*from > ((1 << bit_len) - 1)) || |
| 8745 |
3/4✓ Branch 0 taken 92 times.
✓ Branch 1 taken 587 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 92 times.
|
679 | (!bit_len && delta < 0)) { |
| 8746 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
|
51 | set_rec_bits((1 << bit_len) - 1, bit_ptr, bit_ofs, bit_len); |
| 8747 | 51 | memset(ptr, 0xff, bytes_in_rec); | |
| 8748 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
51 | if (current_thd->is_strict_mode()) |
| 8749 | 51 | set_warning(Sql_condition::SL_WARNING, ER_DATA_TOO_LONG, 1); | |
| 8750 | else | ||
| 8751 | ✗ | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 8752 | 51 | return TYPE_WARN_OUT_OF_RANGE; | |
| 8753 | } | ||
| 8754 | /* delta is >= -1 here */ | ||
| 8755 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 571 times.
|
679 | if (delta > 0) { |
| 8756 |
3/4✓ Branch 0 taken 72 times.
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 72 times.
|
108 | if (bit_len) clr_rec_bits(bit_ptr, bit_ofs, bit_len); |
| 8757 | 108 | memset(ptr, 0, delta); | |
| 8758 | 108 | memcpy(ptr + delta, from, length); | |
| 8759 |
2/2✓ Branch 0 taken 247 times.
✓ Branch 1 taken 324 times.
|
571 | } else if (delta == 0) { |
| 8760 |
4/4✓ Branch 0 taken 191 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 169 times.
|
247 | if (bit_len) clr_rec_bits(bit_ptr, bit_ofs, bit_len); |
| 8761 | 247 | memcpy(ptr, from, length); | |
| 8762 | } else { | ||
| 8763 |
1/2✓ Branch 0 taken 324 times.
✗ Branch 1 not taken.
|
324 | if (bit_len) { |
| 8764 |
2/2✓ Branch 0 taken 137 times.
✓ Branch 1 taken 187 times.
|
324 | set_rec_bits((uchar)*from, bit_ptr, bit_ofs, bit_len); |
| 8765 | 324 | from++; | |
| 8766 | } | ||
| 8767 | 324 | memcpy(ptr, from, bytes_in_rec); | |
| 8768 | } | ||
| 8769 | 679 | return TYPE_OK; | |
| 8770 | } | ||
| 8771 | |||
| 8772 | 261 | type_conversion_status Field_bit::store(double nr) { | |
| 8773 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 260 times.
|
261 | if (nr < LLONG_MIN) |
| 8774 | 1 | return Field_bit::store(static_cast<longlong>(LLONG_MIN), false); | |
| 8775 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 259 times.
|
260 | if (nr > LLONG_MAX_DOUBLE) |
| 8776 | 1 | return Field_bit::store(static_cast<longlong>(LLONG_MAX), false); | |
| 8777 | 259 | return Field_bit::store(static_cast<longlong>(nr), false); | |
| 8778 | } | ||
| 8779 | |||
| 8780 | 99613 | type_conversion_status Field_bit::store(longlong nr, bool) { | |
| 8781 | char buf[8]; | ||
| 8782 | |||
| 8783 | 99613 | mi_int8store(buf, nr); | |
| 8784 |
1/2✓ Branch 0 taken 99613 times.
✗ Branch 1 not taken.
|
199226 | return store(buf, 8, nullptr); |
| 8785 | } | ||
| 8786 | |||
| 8787 | ✗ | type_conversion_status Field_bit::store_decimal(const my_decimal *val) { | |
| 8788 | ✗ | bool has_overflow = false; | |
| 8789 | ✗ | longlong i = convert_decimal2longlong(val, true, &has_overflow); | |
| 8790 | ✗ | type_conversion_status res = store(i, true); | |
| 8791 | ✗ | return has_overflow ? TYPE_WARN_OUT_OF_RANGE : res; | |
| 8792 | } | ||
| 8793 | |||
| 8794 | 27883 | double Field_bit::val_real() const { | |
| 8795 | 27883 | return static_cast<double>(static_cast<ulonglong>(Field_bit::val_int())); | |
| 8796 | } | ||
| 8797 | |||
| 8798 | 451409 | longlong Field_bit::val_int() const { | |
| 8799 |
4/6✓ Branch 0 taken 451409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 451354 times.
✓ Branch 3 taken 55 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 451354 times.
|
451409 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 8800 | 451409 | ulonglong bits = 0; | |
| 8801 |
2/2✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 449854 times.
|
451409 | if (bit_len) { |
| 8802 | 1555 | bits = get_rec_bits(bit_ptr, bit_ofs, bit_len); | |
| 8803 | 1555 | bits <<= (bytes_in_rec * 8); | |
| 8804 | } | ||
| 8805 | |||
| 8806 |
7/9✓ Branch 0 taken 1090 times.
✓ Branch 1 taken 144290 times.
✓ Branch 2 taken 91096 times.
✓ Branch 3 taken 178 times.
✓ Branch 4 taken 99281 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3333 times.
✓ Branch 8 taken 112141 times.
|
451409 | switch (bytes_in_rec) { |
| 8807 | 1090 | case 0: | |
| 8808 | 1090 | return bits; | |
| 8809 | 144290 | case 1: | |
| 8810 | 144290 | return bits | (ulonglong)ptr[0]; | |
| 8811 | 91096 | case 2: | |
| 8812 | 91096 | return bits | mi_uint2korr(ptr); | |
| 8813 | 178 | case 3: | |
| 8814 | 178 | return bits | mi_uint3korr(ptr); | |
| 8815 | 99281 | case 4: | |
| 8816 | 99281 | return bits | mi_uint4korr(ptr); | |
| 8817 | ✗ | case 5: | |
| 8818 | ✗ | return bits | mi_uint5korr(ptr); | |
| 8819 | ✗ | case 6: | |
| 8820 | ✗ | return bits | mi_uint6korr(ptr); | |
| 8821 | 3333 | case 7: | |
| 8822 | 3333 | return bits | mi_uint7korr(ptr); | |
| 8823 | 112141 | default: | |
| 8824 | 112141 | return mi_uint8korr(ptr + bytes_in_rec - sizeof(longlong)); | |
| 8825 | } | ||
| 8826 | } | ||
| 8827 | |||
| 8828 | 36841 | String *Field_bit::val_str(String *val_buffer, String *) const { | |
| 8829 |
4/6✓ Branch 0 taken 36841 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36840 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 36840 times.
|
36841 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 8830 | char buff[sizeof(longlong)]; | ||
| 8831 | 36841 | uint length = min<uint>(pack_length(), sizeof(longlong)); | |
| 8832 |
1/2✓ Branch 0 taken 36841 times.
✗ Branch 1 not taken.
|
36841 | ulonglong bits = val_int(); |
| 8833 | 36841 | mi_int8store(buff, bits); | |
| 8834 | |||
| 8835 |
1/2✓ Branch 0 taken 36841 times.
✗ Branch 1 not taken.
|
36841 | val_buffer->alloc(length); |
| 8836 | 36841 | memcpy(val_buffer->ptr(), buff + 8 - length, length); | |
| 8837 | 36841 | val_buffer->length(length); | |
| 8838 | 36841 | val_buffer->set_charset(&my_charset_bin); | |
| 8839 | 36841 | return val_buffer; | |
| 8840 | } | ||
| 8841 | |||
| 8842 | 16 | my_decimal *Field_bit::val_decimal(my_decimal *deciaml_value) const { | |
| 8843 |
3/6✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 16 times.
|
16 | ASSERT_COLUMN_MARKED_FOR_READ; |
| 8844 | 16 | int2my_decimal(E_DEC_FATAL_ERROR, val_int(), true, deciaml_value); | |
| 8845 | 16 | return deciaml_value; | |
| 8846 | } | ||
| 8847 | |||
| 8848 | /* | ||
| 8849 | Compare two bit fields using pointers within the record. | ||
| 8850 | SYNOPSIS | ||
| 8851 | cmp_max() | ||
| 8852 | a Pointer to field->ptr in first record | ||
| 8853 | b Pointer to field->ptr in second record | ||
| 8854 | DESCRIPTION | ||
| 8855 | This method is used from key_rec_cmp used by merge sorts used | ||
| 8856 | by partitioned index read and later other similar places. | ||
| 8857 | The a and b pointer must be pointers to the field in a record | ||
| 8858 | (not the table->record[0] necessarily) | ||
| 8859 | */ | ||
| 8860 | 6 | int Field_bit::cmp_max(const uchar *a, const uchar *b, uint) const { | |
| 8861 | 6 | ptrdiff_t a_diff = a - ptr; | |
| 8862 | 6 | ptrdiff_t b_diff = b - ptr; | |
| 8863 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (bit_len) { |
| 8864 | int flag; | ||
| 8865 | ✗ | uchar bits_a = get_rec_bits(bit_ptr + a_diff, bit_ofs, bit_len); | |
| 8866 | ✗ | uchar bits_b = get_rec_bits(bit_ptr + b_diff, bit_ofs, bit_len); | |
| 8867 | ✗ | if ((flag = (int)(bits_a - bits_b))) return flag; | |
| 8868 | } | ||
| 8869 | 6 | return memcmp(a, b, pack_length()); | |
| 8870 | } | ||
| 8871 | |||
| 8872 | 4541 | int Field_bit::key_cmp(const uchar *str, uint length) const { | |
| 8873 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4528 times.
|
4541 | if (bit_len) { |
| 8874 | int flag; | ||
| 8875 | 13 | uchar bits = get_rec_bits(bit_ptr, bit_ofs, bit_len); | |
| 8876 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 3 times.
|
13 | if ((flag = (int)(bits - *str))) return flag; |
| 8877 | 3 | str++; | |
| 8878 | 3 | length--; | |
| 8879 | } | ||
| 8880 | 4531 | return memcmp(ptr, str, length); | |
| 8881 | } | ||
| 8882 | |||
| 8883 | 11144 | int Field_bit::cmp_offset(ptrdiff_t row_offset) const { | |
| 8884 |
2/2✓ Branch 0 taken 41 times.
✓ Branch 1 taken 11103 times.
|
11144 | if (bit_len) { |
| 8885 | int flag; | ||
| 8886 | 41 | uchar bits_a = get_rec_bits(bit_ptr, bit_ofs, bit_len); | |
| 8887 | 41 | uchar bits_b = get_rec_bits(bit_ptr + row_offset, bit_ofs, bit_len); | |
| 8888 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
|
41 | if ((flag = (int)(bits_a - bits_b))) return flag; |
| 8889 | } | ||
| 8890 | 11144 | return memcmp(ptr, ptr + row_offset, bytes_in_rec); | |
| 8891 | } | ||
| 8892 | |||
| 8893 | 51773 | size_t Field_bit::get_key_image(uchar *buff, size_t length, imagetype) const { | |
| 8894 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 51743 times.
|
51773 | if (bit_len) { |
| 8895 | 30 | uchar bits = get_rec_bits(bit_ptr, bit_ofs, bit_len); | |
| 8896 | 30 | *buff++ = bits; | |
| 8897 | 30 | length--; | |
| 8898 | } | ||
| 8899 | 51773 | size_t data_length = min(length, static_cast<size_t>(bytes_in_rec)); | |
| 8900 | 51773 | memcpy(buff, ptr, data_length); | |
| 8901 | 51773 | return data_length + 1; | |
| 8902 | } | ||
| 8903 | |||
| 8904 | /** | ||
| 8905 | Save the field metadata for bit fields. | ||
| 8906 | |||
| 8907 | Saves the bit length in the first byte and bytes in record in the | ||
| 8908 | second byte of the field metadata array at index of *metadata_ptr and | ||
| 8909 | *(metadata_ptr + 1). | ||
| 8910 | |||
| 8911 | @param metadata_ptr First byte of field metadata | ||
| 8912 | |||
| 8913 | @returns number of bytes written to metadata_ptr | ||
| 8914 | */ | ||
| 8915 | 32834 | int Field_bit::do_save_field_metadata(uchar *metadata_ptr) const { | |
| 8916 |
1/2✓ Branch 0 taken 32834 times.
✗ Branch 1 not taken.
|
32834 | DBUG_TRACE; |
| 8917 |
3/8✓ Branch 0 taken 32834 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32834 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 32834 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
32834 | DBUG_PRINT("debug", ("bit_len: %d, bytes_in_rec: %d", bit_len, bytes_in_rec)); |
| 8918 | /* | ||
| 8919 | Since this class and Field_bit_as_char have different ideas of | ||
| 8920 | what should be stored here, we compute the values of the metadata | ||
| 8921 | explicitly using the field_length. | ||
| 8922 | */ | ||
| 8923 | 32834 | metadata_ptr[0] = field_length % 8; | |
| 8924 | 32834 | metadata_ptr[1] = field_length / 8; | |
| 8925 | 32834 | return 2; | |
| 8926 | 32834 | } | |
| 8927 | |||
| 8928 | /** | ||
| 8929 | Returns the number of bytes field uses in row-based replication | ||
| 8930 | row packed size. | ||
| 8931 | |||
| 8932 | This method is used in row-based replication to determine the number | ||
| 8933 | of bytes that the field consumes in the row record format. This is | ||
| 8934 | used to skip fields in the master that do not exist on the slave. | ||
| 8935 | |||
| 8936 | @param field_metadata Encoded size in field metadata | ||
| 8937 | |||
| 8938 | @returns The size of the field based on the field metadata. | ||
| 8939 | */ | ||
| 8940 | ✗ | uint Field_bit::pack_length_from_metadata(uint field_metadata) const { | |
| 8941 | ✗ | uint const from_len = (field_metadata >> 8U) & 0x00ff; | |
| 8942 | ✗ | uint const from_bit_len = field_metadata & 0x00ff; | |
| 8943 | ✗ | uint const source_size = from_len + ((from_bit_len > 0) ? 1 : 0); | |
| 8944 | ✗ | return (source_size); | |
| 8945 | } | ||
| 8946 | |||
| 8947 | /** | ||
| 8948 | Check to see if field size is compatible with destination. | ||
| 8949 | |||
| 8950 | This method is used in row-based replication to verify that the slave's | ||
| 8951 | field size is less than or equal to the master's field size. The | ||
| 8952 | encoded field metadata (from the master or source) is decoded and compared | ||
| 8953 | to the size of this field (the slave or destination). | ||
| 8954 | |||
| 8955 | @param field_metadata Encoded size in field metadata | ||
| 8956 | @param mflags Flags from the table map event for the table. | ||
| 8957 | @param order_var Pointer to variable where the order | ||
| 8958 | between the source field and this field | ||
| 8959 | will be returned. | ||
| 8960 | |||
| 8961 | @return @c true | ||
| 8962 | */ | ||
| 8963 | 1310 | bool Field_bit::compatible_field_size(uint field_metadata, Relay_log_info *, | |
| 8964 | uint16 mflags, int *order_var) const { | ||
| 8965 |
1/2✓ Branch 0 taken 1310 times.
✗ Branch 1 not taken.
|
1310 | DBUG_TRACE; |
| 8966 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1310 times.
|
1310 | assert((field_metadata >> 16) == 0); |
| 8967 | 1310 | uint from_bit_len = 8 * (field_metadata >> 8) + (field_metadata & 0xff); | |
| 8968 | 1310 | uint to_bit_len = max_display_length(); | |
| 8969 |
3/8✓ Branch 0 taken 1310 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1310 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1310 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
1310 | DBUG_PRINT("debug", |
| 8970 | ("from_bit_len: %u, to_bit_len: %u", from_bit_len, to_bit_len)); | ||
| 8971 | /* | ||
| 8972 | If the bit length exact flag is clear, we are dealing with an old | ||
| 8973 | master, so we allow some less strict behaviour if replicating by | ||
| 8974 | moving both bit lengths to an even multiple of 8. | ||
| 8975 | |||
| 8976 | We do this by computing the number of bytes to store the field | ||
| 8977 | instead, and then compare the result. | ||
| 8978 | */ | ||
| 8979 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1310 times.
|
1310 | if (!(mflags & Table_map_log_event::TM_BIT_LEN_EXACT_F)) { |
| 8980 | ✗ | from_bit_len = (from_bit_len + 7) / 8; | |
| 8981 | ✗ | to_bit_len = (to_bit_len + 7) / 8; | |
| 8982 | } | ||
| 8983 | |||
| 8984 | 1310 | *order_var = compare(from_bit_len, to_bit_len); | |
| 8985 | 1310 | return true; | |
| 8986 | 1310 | } | |
| 8987 | |||
| 8988 | 411 | void Field_bit::sql_type(String &res) const { | |
| 8989 | 411 | const CHARSET_INFO *cs = res.charset(); | |
| 8990 | 411 | size_t length = cs->cset->snprintf(cs, res.ptr(), res.alloced_length(), | |
| 8991 | 411 | "bit(%d)", (int)field_length); | |
| 8992 | 411 | res.length(length); | |
| 8993 | 411 | } | |
| 8994 | |||
| 8995 | 71505 | uchar *Field_bit::pack(uchar *to, const uchar *from, size_t max_length) const { | |
| 8996 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 71505 times.
|
71505 | if (max_length == 0) { |
| 8997 | ✗ | return to + 1; | |
| 8998 | } | ||
| 8999 | size_t length; | ||
| 9000 |
2/2✓ Branch 0 taken 1180 times.
✓ Branch 1 taken 70325 times.
|
71505 | if (bit_len > 0) { |
| 9001 | /* | ||
| 9002 | We have the following: | ||
| 9003 | |||
| 9004 | ptr Points into a field in record R1 | ||
| 9005 | from Points to a field in a record R2 | ||
| 9006 | bit_ptr Points to the byte (in the null bytes) that holds the | ||
| 9007 | odd bits of R1 | ||
| 9008 | from_bitp Points to the byte that holds the odd bits of R2 | ||
| 9009 | |||
| 9010 | We have the following: | ||
| 9011 | |||
| 9012 | ptr - bit_ptr = from - from_bitp | ||
| 9013 | |||
| 9014 | We want to isolate 'from_bitp', so this gives: | ||
| 9015 | |||
| 9016 | ptr - bit_ptr - from = - from_bitp | ||
| 9017 | - ptr + bit_ptr + from = from_bitp | ||
| 9018 | bit_ptr + from - ptr = from_bitp | ||
| 9019 | */ | ||
| 9020 | 1180 | uchar bits = get_rec_bits(bit_ptr + (from - ptr), bit_ofs, bit_len); | |
| 9021 | 1180 | *to++ = bits; | |
| 9022 | } | ||
| 9023 | 71505 | length = min<size_t>(bytes_in_rec, max_length - (bit_len > 0)); | |
| 9024 | 71505 | memcpy(to, from, length); | |
| 9025 | 71505 | return to + length; | |
| 9026 | } | ||
| 9027 | |||
| 9028 | /** | ||
| 9029 | Unpack a bit field from row data. | ||
| 9030 | |||
| 9031 | This method is used to unpack a bit field from a master whose size | ||
| 9032 | of the field is less than that of the slave. | ||
| 9033 | |||
| 9034 | @param to Destination of the data | ||
| 9035 | @param from Source of the data | ||
| 9036 | @param param_data Bit length (upper) and length (lower) values | ||
| 9037 | |||
| 9038 | @return New pointer into memory based on from + length of the data | ||
| 9039 | */ | ||
| 9040 | 3922 | const uchar *Field_bit::unpack(uchar *to, const uchar *from, uint param_data) { | |
| 9041 |
1/2✓ Branch 0 taken 3922 times.
✗ Branch 1 not taken.
|
3922 | DBUG_TRACE; |
| 9042 |
3/8✓ Branch 0 taken 3922 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3922 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3922 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
3922 | DBUG_PRINT("enter", |
| 9043 | ("to: %p, from: %p, param_data: 0x%x", to, from, param_data)); | ||
| 9044 |
3/8✓ Branch 0 taken 3922 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3922 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3922 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
3922 | DBUG_PRINT("debug", ("bit_ptr: %p, bit_len: %u, bit_ofs: %u", bit_ptr, |
| 9045 | bit_len, bit_ofs)); | ||
| 9046 | 3922 | uint const from_len = (param_data >> 8U) & 0x00ff; | |
| 9047 | 3922 | uint const from_bit_len = param_data & 0x00ff; | |
| 9048 |
3/8✓ Branch 0 taken 3922 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3922 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3922 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
3922 | DBUG_PRINT("debug", |
| 9049 | ("from_len: %u, from_bit_len: %u", from_len, from_bit_len)); | ||
| 9050 | /* | ||
| 9051 | If the parameter data is zero (i.e., undefined), or if the master | ||
| 9052 | and slave have the same sizes, then use the old unpack() method. | ||
| 9053 | */ | ||
| 9054 |
2/2✓ Branch 0 taken 2863 times.
✓ Branch 1 taken 1059 times.
|
3922 | if (param_data == 0 || |
| 9055 |
3/4✓ Branch 0 taken 362 times.
✓ Branch 1 taken 2501 times.
✓ Branch 2 taken 362 times.
✗ Branch 3 not taken.
|
2863 | ((from_bit_len == bit_len) && (from_len == bytes_in_rec))) { |
| 9056 |
2/2✓ Branch 0 taken 657 times.
✓ Branch 1 taken 764 times.
|
1421 | if (bit_len > 0) { |
| 9057 | /* | ||
| 9058 | set_rec_bits is a macro, don't put the post-increment in the | ||
| 9059 | argument since that might cause strange side-effects. | ||
| 9060 | |||
| 9061 | For the choice of the second argument, see the explanation for | ||
| 9062 | Field_bit::pack(). | ||
| 9063 | */ | ||
| 9064 |
2/2✓ Branch 0 taken 195 times.
✓ Branch 1 taken 462 times.
|
657 | set_rec_bits(*from, bit_ptr + (to - ptr), bit_ofs, bit_len); |
| 9065 | 657 | from++; | |
| 9066 | } | ||
| 9067 | 1421 | memcpy(to, from, bytes_in_rec); | |
| 9068 | 1421 | return from + bytes_in_rec; | |
| 9069 | } | ||
| 9070 | |||
| 9071 | /* | ||
| 9072 | We are converting a smaller bit field to a larger one here. | ||
| 9073 | To do that, we first need to construct a raw value for the original | ||
| 9074 | bit value stored in the from buffer. Then that needs to be converted | ||
| 9075 | to the larger field then sent to store() for writing to the field. | ||
| 9076 | Lastly the odd bits need to be masked out if the bytes_in_rec > 0. | ||
| 9077 | Otherwise stray bits can cause spurious values. | ||
| 9078 | */ | ||
| 9079 | 2501 | uint new_len = (field_length + 7) / 8; | |
| 9080 | 2501 | char *value = (char *)my_alloca(new_len); | |
| 9081 | 2501 | memset(value, 0, new_len); | |
| 9082 |
1/2✓ Branch 0 taken 2501 times.
✗ Branch 1 not taken.
|
2501 | uint len = from_len + ((from_bit_len > 0) ? 1 : 0); |
| 9083 | 2501 | memcpy(value + (new_len - len), from, len); | |
| 9084 | /* | ||
| 9085 | Mask out the unused bits in the partial byte. | ||
| 9086 | TODO: Add code to the master to always mask these bits and remove | ||
| 9087 | the following. | ||
| 9088 | */ | ||
| 9089 |
3/4✓ Branch 0 taken 2501 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1005 times.
✓ Branch 3 taken 1496 times.
|
2501 | if ((from_bit_len > 0) && (from_len > 0)) |
| 9090 | 1005 | value[new_len - len] = value[new_len - len] & ((1U << from_bit_len) - 1); | |
| 9091 | 2501 | bitmap_set_bit(table->write_set, field_index()); | |
| 9092 |
1/2✓ Branch 0 taken 2501 times.
✗ Branch 1 not taken.
|
2501 | store(value, new_len, system_charset_info); |
| 9093 | 2501 | return from + len; | |
| 9094 | 3922 | } | |
| 9095 | |||
| 9096 | 540 | void Field_bit::set_default() { | |
| 9097 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 539 times.
|
540 | if (bit_len > 0) { |
| 9098 | 1 | ptrdiff_t offset = table->default_values_offset(); | |
| 9099 | 1 | uchar bits = get_rec_bits(bit_ptr + offset, bit_ofs, bit_len); | |
| 9100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | set_rec_bits(bits, bit_ptr, bit_ofs, bit_len); |
| 9101 | } | ||
| 9102 | 540 | Field::set_default(); | |
| 9103 | 540 | } | |
| 9104 | |||
| 9105 | /* | ||
| 9106 | Bit field support for non-MyISAM tables. | ||
| 9107 | */ | ||
| 9108 | |||
| 9109 | 13410 | Field_bit_as_char::Field_bit_as_char(uchar *ptr_arg, uint32 len_arg, | |
| 9110 | uchar *null_ptr_arg, uchar null_bit_arg, | ||
| 9111 | uchar auto_flags_arg, | ||
| 9112 | 13410 | const char *field_name_arg) | |
| 9113 | : Field_bit(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, nullptr, 0, | ||
| 9114 | 13410 | auto_flags_arg, field_name_arg) { | |
| 9115 | 13410 | set_flag(UNSIGNED_FLAG); | |
| 9116 | 13410 | bit_len = 0; | |
| 9117 | 13410 | bytes_in_rec = (len_arg + 7) / 8; | |
| 9118 | 13410 | } | |
| 9119 | |||
| 9120 | 108739 | type_conversion_status Field_bit_as_char::store(const char *from, size_t length, | |
| 9121 | const CHARSET_INFO *) { | ||
| 9122 |
4/6✓ Branch 0 taken 108739 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 108694 times.
✓ Branch 3 taken 45 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 108694 times.
|
108739 | ASSERT_COLUMN_MARKED_FOR_WRITE; |
| 9123 | int delta; | ||
| 9124 | 108739 | uchar bits = (uchar)(field_length & 7); | |
| 9125 | |||
| 9126 |
4/4✓ Branch 0 taken 782358 times.
✓ Branch 1 taken 2291 times.
✓ Branch 2 taken 675910 times.
✓ Branch 3 taken 106448 times.
|
784649 | for (; length && !*from; from++, length--) |
| 9127 | ; // skip left 0's | ||
| 9128 | 108739 | delta = bytes_in_rec - static_cast<int>(length); | |
| 9129 | |||
| 9130 |
4/4✓ Branch 0 taken 101491 times.
✓ Branch 1 taken 7248 times.
✓ Branch 2 taken 30929 times.
✓ Branch 3 taken 70562 times.
|
108739 | if (delta < 0 || |
| 9131 |
4/4✓ Branch 0 taken 12835 times.
✓ Branch 1 taken 18094 times.
✓ Branch 2 taken 8866 times.
✓ Branch 3 taken 3969 times.
|
30929 | (delta == 0 && bits && (uint)(uchar)*from >= (uint)(1 << bits))) { |
| 9132 | 16114 | memset(ptr, 0xff, bytes_in_rec); | |
| 9133 |
2/2✓ Branch 0 taken 11980 times.
✓ Branch 1 taken 4134 times.
|
16114 | if (bits) *ptr &= ((1 << bits) - 1); /* set first uchar */ |
| 9134 |
2/2✓ Branch 0 taken 179 times.
✓ Branch 1 taken 15935 times.
|
16114 | if (current_thd->is_strict_mode()) |
| 9135 | 179 | set_warning(Sql_condition::SL_WARNING, ER_DATA_TOO_LONG, 1); | |
| 9136 | else | ||
| 9137 | 15935 | set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1); | |
| 9138 | 16114 | return TYPE_WARN_OUT_OF_RANGE; | |
| 9139 | } | ||
| 9140 | 92625 | memset(ptr, 0, delta); | |
| 9141 | 92625 | memcpy(ptr + delta, from, length); | |
| 9142 | 92625 | return TYPE_OK; | |
| 9143 | } | ||
| 9144 | |||
| 9145 | 4696 | void Field_bit_as_char::sql_type(String &res) const { | |
| 9146 | 4696 | const CHARSET_INFO *cs = res.charset(); | |
| 9147 | 4696 | size_t length = cs->cset->snprintf(cs, res.ptr(), res.alloced_length(), | |
| 9148 | 4696 | "bit(%d)", (int)field_length); | |
| 9149 | 4696 | res.length(length); | |
| 9150 | 4696 | } | |
| 9151 | |||
| 9152 | /***************************************************************************** | ||
| 9153 | Handling of field and Create_field | ||
| 9154 | *****************************************************************************/ | ||
| 9155 | |||
| 9156 | /** | ||
| 9157 | Calculate key length for field from its type, length and other attributes. | ||
| 9158 | |||
| 9159 | @note for string fields "length" parameter is assumed to take into account | ||
| 9160 | character set. | ||
| 9161 | |||
| 9162 | TODO: Get rid of this function as its code is redundant with | ||
| 9163 | Field::key_length() code. However creation of Field object using | ||
| 9164 | make_field() just to call Field::key_length() is probably overkill. | ||
| 9165 | */ | ||
| 9166 | |||
| 9167 | 80876082 | uint32 calc_key_length(enum_field_types sql_type, uint32 length, | |
| 9168 | uint32 decimals, bool is_unsigned, uint32 elements) { | ||
| 9169 | uint precision; | ||
| 9170 |
7/7✓ Branch 0 taken 5239239 times.
✓ Branch 1 taken 10689954 times.
✓ Branch 2 taken 11185883 times.
✓ Branch 3 taken 1870602 times.
✓ Branch 4 taken 6351 times.
✓ Branch 5 taken 37176 times.
✓ Branch 6 taken 51846877 times.
|
80876082 | switch (sql_type) { |
| 9171 | 5239239 | case MYSQL_TYPE_TINY_BLOB: | |
| 9172 | case MYSQL_TYPE_MEDIUM_BLOB: | ||
| 9173 | case MYSQL_TYPE_LONG_BLOB: | ||
| 9174 | case MYSQL_TYPE_BLOB: | ||
| 9175 | case MYSQL_TYPE_GEOMETRY: | ||
| 9176 | case MYSQL_TYPE_JSON: | ||
| 9177 | 5239239 | return 0; | |
| 9178 | 10689954 | case MYSQL_TYPE_VARCHAR: | |
| 9179 | 10689954 | return length; | |
| 9180 | 11185883 | case MYSQL_TYPE_ENUM: | |
| 9181 | 11185883 | return get_enum_pack_length(elements); | |
| 9182 | 1870602 | case MYSQL_TYPE_SET: | |
| 9183 | 1870602 | return get_set_pack_length(elements); | |
| 9184 | 6351 | case MYSQL_TYPE_BIT: | |
| 9185 |
2/2✓ Branch 0 taken 5141 times.
✓ Branch 1 taken 1210 times.
|
6351 | return length / 8 + (length & 7 ? 1 : 0); |
| 9186 | break; | ||
| 9187 | 37176 | case MYSQL_TYPE_NEWDECIMAL: | |
| 9188 | 74352 | precision = std::min<uint>( | |
| 9189 | 37176 | my_decimal_length_to_precision(length, decimals, is_unsigned), | |
| 9190 | 37176 | DECIMAL_MAX_PRECISION); | |
| 9191 | 37176 | return my_decimal_get_binary_size(precision, decimals); | |
| 9192 | 51846877 | default: | |
| 9193 | 51846877 | return calc_pack_length(sql_type, length); | |
| 9194 | } | ||
| 9195 | } | ||
| 9196 | |||
| 9197 | 93108 | enum_field_types get_blob_type_from_length(size_t length) { | |
| 9198 | enum_field_types type; | ||
| 9199 |
2/2✓ Branch 0 taken 3016 times.
✓ Branch 1 taken 90092 times.
|
93108 | if (length < 256) |
| 9200 | 3016 | type = MYSQL_TYPE_TINY_BLOB; | |
| 9201 |
2/2✓ Branch 0 taken 81519 times.
✓ Branch 1 taken 8573 times.
|
90092 | else if (length < 65536) |
| 9202 | 81519 | type = MYSQL_TYPE_BLOB; | |
| 9203 |
2/2✓ Branch 0 taken 2466 times.
✓ Branch 1 taken 6107 times.
|
8573 | else if (length < 256L * 256L * 256L) |
| 9204 | 2466 | type = MYSQL_TYPE_MEDIUM_BLOB; | |
| 9205 | else | ||
| 9206 | 6107 | type = MYSQL_TYPE_LONG_BLOB; | |
| 9207 | 93108 | return type; | |
| 9208 | } | ||
| 9209 | |||
| 9210 | 102867232 | size_t calc_pack_length(enum_field_types type, size_t length) { | |
| 9211 |
18/26✓ Branch 0 taken 4664025 times.
✓ Branch 1 taken 9131962 times.
✓ Branch 2 taken 5530630 times.
✓ Branch 3 taken 785010 times.
✓ Branch 4 taken 4716769 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 98289 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3097187 times.
✓ Branch 9 taken 25506977 times.
✓ Branch 10 taken 236791 times.
✓ Branch 11 taken 116269 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 875572 times.
✓ Branch 14 taken 34840727 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 54905 times.
✓ Branch 17 taken 4564030 times.
✓ Branch 18 taken 4488745 times.
✓ Branch 19 taken 2660468 times.
✓ Branch 20 taken 30263 times.
✓ Branch 21 taken 1468616 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
102867232 | switch (type) { |
| 9212 | 4664025 | case MYSQL_TYPE_VAR_STRING: | |
| 9213 | case MYSQL_TYPE_STRING: | ||
| 9214 | case MYSQL_TYPE_DECIMAL: | ||
| 9215 | 4664025 | return (length); | |
| 9216 | 9131962 | case MYSQL_TYPE_VARCHAR: | |
| 9217 |
2/2✓ Branch 0 taken 5019843 times.
✓ Branch 1 taken 4112119 times.
|
9131962 | return (length + (length < 256 ? 1 : 2)); |
| 9218 | 5530630 | case MYSQL_TYPE_BOOL: | |
| 9219 | case MYSQL_TYPE_YEAR: | ||
| 9220 | case MYSQL_TYPE_TINY: | ||
| 9221 | 5530630 | return 1; | |
| 9222 | 785010 | case MYSQL_TYPE_SHORT: | |
| 9223 | 785010 | return 2; | |
| 9224 | 4716769 | case MYSQL_TYPE_INT24: | |
| 9225 | case MYSQL_TYPE_NEWDATE: | ||
| 9226 | 4716769 | return 3; | |
| 9227 | ✗ | case MYSQL_TYPE_TIME: | |
| 9228 | ✗ | return 3; | |
| 9229 | 98289 | case MYSQL_TYPE_TIME2: | |
| 9230 | return length > MAX_TIME_WIDTH | ||
| 9231 |
2/2✓ Branch 0 taken 40112 times.
✓ Branch 1 taken 58177 times.
|
98289 | ? my_time_binary_length(length - MAX_TIME_WIDTH - 1) |
| 9232 | 98289 | : 3; | |
| 9233 | ✗ | case MYSQL_TYPE_TIMESTAMP: | |
| 9234 | ✗ | return 4; | |
| 9235 | 3097187 | case MYSQL_TYPE_TIMESTAMP2: | |
| 9236 | return length > MAX_DATETIME_WIDTH | ||
| 9237 |
2/2✓ Branch 0 taken 581457 times.
✓ Branch 1 taken 2515730 times.
|
3097187 | ? my_timestamp_binary_length(length - MAX_DATETIME_WIDTH - 1) |
| 9238 | 3097187 | : 4; | |
| 9239 | 25506977 | case MYSQL_TYPE_DATE: | |
| 9240 | case MYSQL_TYPE_LONG: | ||
| 9241 | 25506977 | return 4; | |
| 9242 | 236791 | case MYSQL_TYPE_FLOAT: | |
| 9243 | 236791 | return sizeof(float); | |
| 9244 | 116269 | case MYSQL_TYPE_DOUBLE: | |
| 9245 | 116269 | return sizeof(double); | |
| 9246 | ✗ | case MYSQL_TYPE_DATETIME: | |
| 9247 | ✗ | return 8; | |
| 9248 | 875572 | case MYSQL_TYPE_DATETIME2: | |
| 9249 | return length > MAX_DATETIME_WIDTH | ||
| 9250 |
2/2✓ Branch 0 taken 7473 times.
✓ Branch 1 taken 868099 times.
|
875572 | ? my_datetime_binary_length(length - MAX_DATETIME_WIDTH - 1) |
| 9251 | 875572 | : 5; | |
| 9252 | 34840727 | case MYSQL_TYPE_LONGLONG: | |
| 9253 | 34840727 | return 8; /* Don't crash if no longlong */ | |
| 9254 | ✗ | case MYSQL_TYPE_NULL: | |
| 9255 | ✗ | return 0; | |
| 9256 | 54905 | case MYSQL_TYPE_TINY_BLOB: | |
| 9257 | 54905 | return 1 + portable_sizeof_char_ptr; | |
| 9258 | 4564030 | case MYSQL_TYPE_BLOB: | |
| 9259 | 4564030 | return 2 + portable_sizeof_char_ptr; | |
| 9260 | 4488745 | case MYSQL_TYPE_MEDIUM_BLOB: | |
| 9261 | 4488745 | return 3 + portable_sizeof_char_ptr; | |
| 9262 | 2660468 | case MYSQL_TYPE_LONG_BLOB: | |
| 9263 | 2660468 | return 4 + portable_sizeof_char_ptr; | |
| 9264 | 30263 | case MYSQL_TYPE_GEOMETRY: | |
| 9265 | 30263 | return 4 + portable_sizeof_char_ptr; | |
| 9266 | 1468616 | case MYSQL_TYPE_JSON: | |
| 9267 | 1468616 | return 4 + portable_sizeof_char_ptr; | |
| 9268 | ✗ | case MYSQL_TYPE_SET: | |
| 9269 | case MYSQL_TYPE_ENUM: | ||
| 9270 | case MYSQL_TYPE_NEWDECIMAL: | ||
| 9271 | ✗ | assert(false); | |
| 9272 | return 0; // This shouldn't happen | ||
| 9273 | ✗ | case MYSQL_TYPE_BIT: | |
| 9274 | ✗ | return length / 8; | |
| 9275 | ✗ | case MYSQL_TYPE_INVALID: | |
| 9276 | case MYSQL_TYPE_TYPED_ARRAY: | ||
| 9277 | ✗ | break; | |
| 9278 | } | ||
| 9279 | ✗ | assert(false); | |
| 9280 | return 0; | ||
| 9281 | } | ||
| 9282 | |||
| 9283 | 22549890 | size_t calc_pack_length(dd::enum_column_types type, size_t char_length, | |
| 9284 | size_t elements_count, bool treat_bit_as_char, | ||
| 9285 | uint numeric_scale, bool is_unsigned) { | ||
| 9286 | 22549890 | size_t pack_length = 0; | |
| 9287 | |||
| 9288 |
6/6✓ Branch 0 taken 8082565 times.
✓ Branch 1 taken 3231438 times.
✓ Branch 2 taken 208666 times.
✓ Branch 3 taken 6902 times.
✓ Branch 4 taken 25009 times.
✓ Branch 5 taken 10995310 times.
|
22549890 | switch (type) { |
| 9289 | 8082565 | case dd::enum_column_types::TINY_BLOB: | |
| 9290 | case dd::enum_column_types::MEDIUM_BLOB: | ||
| 9291 | case dd::enum_column_types::LONG_BLOB: | ||
| 9292 | case dd::enum_column_types::BLOB: | ||
| 9293 | case dd::enum_column_types::GEOMETRY: | ||
| 9294 | case dd::enum_column_types::VAR_STRING: | ||
| 9295 | case dd::enum_column_types::STRING: | ||
| 9296 | case dd::enum_column_types::VARCHAR: | ||
| 9297 | // The length is already calculated in number of bytes, no need | ||
| 9298 | // to multiply by number of bytes per symbol. | ||
| 9299 | 8082565 | pack_length = calc_pack_length(dd_get_old_field_type(type), char_length); | |
| 9300 | 8082564 | break; | |
| 9301 | 3231438 | case dd::enum_column_types::ENUM: | |
| 9302 | 3231438 | pack_length = get_enum_pack_length(elements_count); | |
| 9303 | 3231438 | break; | |
| 9304 | 208666 | case dd::enum_column_types::SET: | |
| 9305 | 208666 | pack_length = get_set_pack_length(elements_count); | |
| 9306 | 208666 | break; | |
| 9307 | 6902 | case dd::enum_column_types::BIT: { | |
| 9308 |
2/2✓ Branch 0 taken 6367 times.
✓ Branch 1 taken 535 times.
|
6902 | if (treat_bit_as_char) |
| 9309 | 6367 | pack_length = ((char_length + 7) & ~7) / 8; | |
| 9310 | else | ||
| 9311 | 535 | pack_length = char_length / 8; | |
| 9312 | 6902 | } break; | |
| 9313 | 25009 | case dd::enum_column_types::NEWDECIMAL: { | |
| 9314 | 25009 | uint decimals = numeric_scale; | |
| 9315 | 25009 | uint precision = std::min( | |
| 9316 | 25009 | my_decimal_length_to_precision(char_length, decimals, is_unsigned), | |
| 9317 | 25009 | uint(DECIMAL_MAX_PRECISION)); | |
| 9318 |
2/4✓ Branch 0 taken 25009 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25009 times.
✗ Branch 3 not taken.
|
25009 | assert((precision <= DECIMAL_MAX_PRECISION) && |
| 9319 | (decimals <= DECIMAL_MAX_SCALE)); | ||
| 9320 | 25009 | pack_length = my_decimal_get_binary_size(precision, decimals); | |
| 9321 | 25009 | } break; | |
| 9322 | 10995310 | default: | |
| 9323 | 10995310 | pack_length = calc_pack_length(dd_get_old_field_type(type), char_length); | |
| 9324 | 10995311 | break; | |
| 9325 | } | ||
| 9326 | 22549890 | return pack_length; | |
| 9327 | } | ||
| 9328 | |||
| 9329 | 48335417 | Field *make_field(MEM_ROOT *mem_root, TABLE_SHARE *share, uchar *ptr, | |
| 9330 | size_t field_length, uchar *null_pos, uchar null_bit, | ||
| 9331 | enum_field_types field_type, | ||
| 9332 | const CHARSET_INFO *field_charset, | ||
| 9333 | Field::geometry_type geom_type, uchar auto_flags, | ||
| 9334 | TYPELIB *interval, const char *field_name, bool is_nullable, | ||
| 9335 | bool is_zerofill, bool is_unsigned, uint decimals, | ||
| 9336 | bool treat_bit_as_char, uint pack_length_override, | ||
| 9337 | std::optional<gis::srid_t> srid, bool is_array) { | ||
| 9338 | 48335417 | uchar *bit_ptr = nullptr; | |
| 9339 | 48335417 | uchar bit_offset = 0; | |
| 9340 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48335417 times.
|
48335417 | assert(mem_root); |
| 9341 | |||
| 9342 |
4/4✓ Branch 0 taken 14709 times.
✓ Branch 1 taken 48320708 times.
✓ Branch 2 taken 1303 times.
✓ Branch 3 taken 13406 times.
|
48335417 | if (field_type == MYSQL_TYPE_BIT && !treat_bit_as_char) { |
| 9343 | 1303 | bit_ptr = null_pos; | |
| 9344 | 1303 | bit_offset = null_bit; | |
| 9345 |
2/2✓ Branch 0 taken 1164 times.
✓ Branch 1 taken 139 times.
|
1303 | if (is_nullable) // if null field |
| 9346 | { | ||
| 9347 | 1164 | bit_ptr += (null_bit == 7); // shift bit_ptr and bit_offset | |
| 9348 | 1164 | bit_offset = (bit_offset + 1) & 7; | |
| 9349 | } | ||
| 9350 | } | ||
| 9351 | |||
| 9352 |
2/2✓ Branch 0 taken 30268706 times.
✓ Branch 1 taken 18066711 times.
|
48335417 | if (!is_nullable) { |
| 9353 | 30268706 | null_pos = nullptr; | |
| 9354 | 30268706 | null_bit = 0; | |
| 9355 | } else { | ||
| 9356 | 18066711 | null_bit = ((uchar)1) << null_bit; | |
| 9357 | } | ||
| 9358 | |||
| 9359 |
2/2✓ Branch 0 taken 2281440 times.
✓ Branch 1 taken 46053983 times.
|
48335417 | if (is_temporal_real_type(field_type)) field_charset = &my_charset_numeric; |
| 9360 | |||
| 9361 |
4/4✓ Branch 0 taken 1821 times.
✓ Branch 1 taken 48333608 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 1816 times.
|
48335423 | DBUG_PRINT("debug", ("field_type: %d, field_length: %zu, " |
| 9362 | "interval: %p, is_array: %s", | ||
| 9363 | field_type, field_length, interval, | ||
| 9364 | (is_array ? "true" : "false"))); | ||
| 9365 | |||
| 9366 |
2/2✓ Branch 0 taken 2216 times.
✓ Branch 1 taken 48333205 times.
|
48335421 | if (is_array) { |
| 9367 | // See Item_func_array_cast::resolve_type() for supported types | ||
| 9368 |
3/4✓ Branch 0 taken 1947 times.
✓ Branch 1 taken 168 times.
✓ Branch 2 taken 101 times.
✗ Branch 3 not taken.
|
2216 | switch (field_type) { |
| 9369 | 1947 | case MYSQL_TYPE_VARCHAR: | |
| 9370 | case MYSQL_TYPE_NEWDECIMAL: | ||
| 9371 | case MYSQL_TYPE_LONGLONG: | ||
| 9372 | case MYSQL_TYPE_NEWDATE: | ||
| 9373 | 1947 | break; | |
| 9374 | 168 | case MYSQL_TYPE_TIME2: | |
| 9375 | 168 | decimals = (field_length > MAX_TIME_WIDTH) | |
| 9376 | 168 | ? field_length - 1 - MAX_TIME_WIDTH | |
| 9377 | : 0; | ||
| 9378 | 168 | break; | |
| 9379 | 101 | case MYSQL_TYPE_DATETIME2: | |
| 9380 | 101 | decimals = (field_length > MAX_DATETIME_WIDTH) | |
| 9381 | 101 | ? field_length - 1 - MAX_DATETIME_WIDTH | |
| 9382 | : 0; | ||
| 9383 | 101 | break; | |
| 9384 | ✗ | case MYSQL_TYPE_YEAR: | |
| 9385 | default: | ||
| 9386 | ✗ | assert(0); // Shouldn't happen | |
| 9387 | return nullptr; | ||
| 9388 | } | ||
| 9389 | /* | ||
| 9390 | Field_json constructor expects number of bytes used to represent length | ||
| 9391 | of the underlying blob as parameter and not the real field pack_length. | ||
| 9392 | JSON is used as array storage. | ||
| 9393 | */ | ||
| 9394 | 2216 | uint pack_length = calc_pack_length(MYSQL_TYPE_JSON, field_length) - | |
| 9395 | 2216 | portable_sizeof_char_ptr; | |
| 9396 | |||
| 9397 | return new (mem_root) Field_typed_array( | ||
| 9398 | field_type, is_unsigned, field_length, decimals, ptr, null_pos, | ||
| 9399 |
2/4✓ Branch 0 taken 2216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2216 times.
✗ Branch 3 not taken.
|
2216 | null_bit, auto_flags, field_name, share, pack_length, field_charset); |
| 9400 | } | ||
| 9401 | /* | ||
| 9402 | FRMs from 3.23/4.0 can have strings with field_type == MYSQL_TYPE_DECIMAL. | ||
| 9403 | We should not be getting them after upgrade to new data-dictionary. | ||
| 9404 | */ | ||
| 9405 | |||
| 9406 |
26/27✓ Branch 0 taken 2107705 times.
✓ Branch 1 taken 10003219 times.
✓ Branch 2 taken 5937701 times.
✓ Branch 3 taken 14121 times.
✓ Branch 4 taken 729386 times.
✓ Branch 5 taken 5406459 times.
✓ Branch 6 taken 379317 times.
✓ Branch 7 taken 1292 times.
✓ Branch 8 taken 906765 times.
✓ Branch 9 taken 213882 times.
✓ Branch 10 taken 43257 times.
✓ Branch 11 taken 2002733 times.
✓ Branch 12 taken 374183 times.
✓ Branch 13 taken 36684 times.
✓ Branch 14 taken 5499321 times.
✓ Branch 15 taken 12381454 times.
✓ Branch 16 taken 4 times.
✓ Branch 17 taken 1709259 times.
✓ Branch 18 taken 10335 times.
✓ Branch 19 taken 23952 times.
✓ Branch 20 taken 3 times.
✓ Branch 21 taken 152055 times.
✓ Branch 22 taken 26907 times.
✓ Branch 23 taken 358496 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 14709 times.
✓ Branch 26 taken 6 times.
|
48333205 | switch (field_type) { |
| 9407 | 2107705 | case MYSQL_TYPE_VAR_STRING: | |
| 9408 | case MYSQL_TYPE_STRING: | ||
| 9409 | return new (mem_root) Field_string(ptr, field_length, null_pos, null_bit, | ||
| 9410 |
2/4✓ Branch 0 taken 2107705 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2107705 times.
✗ Branch 3 not taken.
|
2107705 | auto_flags, field_name, field_charset); |
| 9411 | 10003219 | case MYSQL_TYPE_VARCHAR: | |
| 9412 | return new (mem_root) Field_varstring( | ||
| 9413 | ptr, field_length, HA_VARCHAR_PACKLENGTH(field_length), null_pos, | ||
| 9414 |
4/6✓ Branch 0 taken 10003220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5291091 times.
✓ Branch 3 taken 4712129 times.
✓ Branch 4 taken 10003221 times.
✗ Branch 5 not taken.
|
10003219 | null_bit, auto_flags, field_name, share, field_charset); |
| 9415 | 5937701 | case MYSQL_TYPE_BLOB: | |
| 9416 | case MYSQL_TYPE_MEDIUM_BLOB: | ||
| 9417 | case MYSQL_TYPE_TINY_BLOB: | ||
| 9418 | case MYSQL_TYPE_LONG_BLOB: { | ||
| 9419 | /* | ||
| 9420 | Field_blob constructor expects number of bytes used to represent length | ||
| 9421 | of the blob as parameter and not the real field pack_length. | ||
| 9422 | */ | ||
| 9423 | uint pack_length = | ||
| 9424 | 5937701 | calc_pack_length(field_type, field_length) - portable_sizeof_char_ptr; | |
| 9425 | |||
| 9426 | return new (mem_root) | ||
| 9427 | Field_blob(ptr, null_pos, null_bit, auto_flags, field_name, share, | ||
| 9428 |
2/4✓ Branch 0 taken 5937701 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5937701 times.
✗ Branch 3 not taken.
|
5937701 | pack_length, field_charset); |
| 9429 | } | ||
| 9430 | 14121 | case MYSQL_TYPE_GEOMETRY: { | |
| 9431 | /* | ||
| 9432 | Field_geom constructor expects number of bytes used to represent length | ||
| 9433 | of the underlying blob as parameter and not the real field pack_length. | ||
| 9434 | */ | ||
| 9435 | uint pack_length = | ||
| 9436 | 14121 | calc_pack_length(field_type, field_length) - portable_sizeof_char_ptr; | |
| 9437 | |||
| 9438 | return new (mem_root) | ||
| 9439 | Field_geom(ptr, null_pos, null_bit, auto_flags, field_name, share, | ||
| 9440 |
2/4✓ Branch 0 taken 14121 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14121 times.
✗ Branch 3 not taken.
|
14121 | pack_length, geom_type, srid); |
| 9441 | } | ||
| 9442 | 729386 | case MYSQL_TYPE_JSON: { | |
| 9443 | /* | ||
| 9444 | Field_json constructor expects number of bytes used to represent length | ||
| 9445 | of the underlying blob as parameter and not the real field pack_length. | ||
| 9446 | */ | ||
| 9447 | uint pack_length = | ||
| 9448 | 729386 | calc_pack_length(field_type, field_length) - portable_sizeof_char_ptr; | |
| 9449 | |||
| 9450 | return new (mem_root) Field_json(ptr, null_pos, null_bit, auto_flags, | ||
| 9451 |
2/4✓ Branch 0 taken 729386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 729386 times.
✗ Branch 3 not taken.
|
729386 | field_name, share, pack_length); |
| 9452 | } | ||
| 9453 | 5406459 | case MYSQL_TYPE_ENUM: | |
| 9454 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5406459 times.
|
5406459 | assert(interval); |
| 9455 | return new (mem_root) Field_enum( | ||
| 9456 | ptr, field_length, null_pos, null_bit, auto_flags, field_name, | ||
| 9457 |
2/2✓ Branch 0 taken 5406458 times.
✓ Branch 1 taken 1 times.
|
5406459 | (pack_length_override ? pack_length_override |
| 9458 | 5406458 | : get_enum_pack_length(interval->count)), | |
| 9459 |
2/4✓ Branch 0 taken 5406459 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5406459 times.
✗ Branch 3 not taken.
|
5406459 | interval, field_charset); |
| 9460 | 379317 | case MYSQL_TYPE_SET: | |
| 9461 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 379317 times.
|
379317 | assert(interval); |
| 9462 | return new (mem_root) Field_set( | ||
| 9463 | ptr, field_length, null_pos, null_bit, auto_flags, field_name, | ||
| 9464 |
2/2✓ Branch 0 taken 379310 times.
✓ Branch 1 taken 7 times.
|
379317 | (pack_length_override ? pack_length_override |
| 9465 | 379310 | : get_set_pack_length(interval->count)), | |
| 9466 |
2/4✓ Branch 0 taken 379317 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 379317 times.
✗ Branch 3 not taken.
|
379317 | interval, field_charset); |
| 9467 | 1292 | case MYSQL_TYPE_DECIMAL: | |
| 9468 | return new (mem_root) | ||
| 9469 | Field_decimal(ptr, field_length, null_pos, null_bit, auto_flags, | ||
| 9470 |
2/4✓ Branch 0 taken 1292 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1292 times.
✗ Branch 3 not taken.
|
1292 | field_name, decimals, is_zerofill, is_unsigned); |
| 9471 | 906765 | case MYSQL_TYPE_NEWDECIMAL: | |
| 9472 | return new (mem_root) | ||
| 9473 | Field_new_decimal(ptr, field_length, null_pos, null_bit, auto_flags, | ||
| 9474 |
2/4✓ Branch 0 taken 906765 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 906765 times.
✗ Branch 3 not taken.
|
906765 | field_name, decimals, is_zerofill, is_unsigned); |
| 9475 | 213882 | case MYSQL_TYPE_FLOAT: | |
| 9476 | return new (mem_root) | ||
| 9477 | Field_float(ptr, field_length, null_pos, null_bit, auto_flags, | ||
| 9478 |
2/4✓ Branch 0 taken 213882 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 213882 times.
✗ Branch 3 not taken.
|
213882 | field_name, decimals, is_zerofill, is_unsigned); |
| 9479 | 43257 | case MYSQL_TYPE_DOUBLE: | |
| 9480 | return new (mem_root) | ||
| 9481 | Field_double(ptr, field_length, null_pos, null_bit, auto_flags, | ||
| 9482 |
2/4✓ Branch 0 taken 43257 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43257 times.
✗ Branch 3 not taken.
|
43257 | field_name, decimals, is_zerofill, is_unsigned); |
| 9483 | 2002733 | case MYSQL_TYPE_TINY: | |
| 9484 | return new (mem_root) | ||
| 9485 | Field_tiny(ptr, field_length, null_pos, null_bit, auto_flags, | ||
| 9486 |
2/4✓ Branch 0 taken 2002733 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2002733 times.
✗ Branch 3 not taken.
|
2002733 | field_name, is_zerofill, is_unsigned); |
| 9487 | 374183 | case MYSQL_TYPE_SHORT: | |
| 9488 | return new (mem_root) | ||
| 9489 | Field_short(ptr, field_length, null_pos, null_bit, auto_flags, | ||
| 9490 |
2/4✓ Branch 0 taken 374183 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 374183 times.
✗ Branch 3 not taken.
|
374183 | field_name, is_zerofill, is_unsigned); |
| 9491 | 36684 | case MYSQL_TYPE_INT24: | |
| 9492 | return new (mem_root) | ||
| 9493 | Field_medium(ptr, field_length, null_pos, null_bit, auto_flags, | ||
| 9494 |
2/4✓ Branch 0 taken 36684 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36684 times.
✗ Branch 3 not taken.
|
36684 | field_name, is_zerofill, is_unsigned); |
| 9495 | 5499321 | case MYSQL_TYPE_LONG: | |
| 9496 | return new (mem_root) | ||
| 9497 | Field_long(ptr, field_length, null_pos, null_bit, auto_flags, | ||
| 9498 |
2/4✓ Branch 0 taken 5499323 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5499328 times.
✗ Branch 3 not taken.
|
5499321 | field_name, is_zerofill, is_unsigned); |
| 9499 | 12381454 | case MYSQL_TYPE_LONGLONG: | |
| 9500 | return new (mem_root) | ||
| 9501 | Field_longlong(ptr, field_length, null_pos, null_bit, auto_flags, | ||
| 9502 |
2/4✓ Branch 0 taken 12381454 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12381454 times.
✗ Branch 3 not taken.
|
12381454 | field_name, is_zerofill, is_unsigned); |
| 9503 | 4 | case MYSQL_TYPE_TIMESTAMP: | |
| 9504 | return new (mem_root) Field_timestamp(ptr, field_length, null_pos, | ||
| 9505 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | null_bit, auto_flags, field_name); |
| 9506 | 1709259 | case MYSQL_TYPE_TIMESTAMP2: | |
| 9507 | return new (mem_root) | ||
| 9508 | Field_timestampf(ptr, null_pos, null_bit, auto_flags, field_name, | ||
| 9509 | field_length > MAX_DATETIME_WIDTH | ||
| 9510 | 1709259 | ? field_length - 1 - MAX_DATETIME_WIDTH | |
| 9511 |
2/4✓ Branch 0 taken 1709259 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1709259 times.
✗ Branch 3 not taken.
|
1709259 | : 0); |
| 9512 | 10335 | case MYSQL_TYPE_YEAR: | |
| 9513 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10335 times.
|
10335 | assert(field_length == 4); // Field_year is only for length 4. |
| 9514 | return new (mem_root) | ||
| 9515 |
2/4✓ Branch 0 taken 10335 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10335 times.
✗ Branch 3 not taken.
|
10335 | Field_year(ptr, null_pos, null_bit, auto_flags, field_name); |
| 9516 | 23952 | case MYSQL_TYPE_NEWDATE: | |
| 9517 | return new (mem_root) | ||
| 9518 |
2/4✓ Branch 0 taken 23952 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23952 times.
✗ Branch 3 not taken.
|
23952 | Field_newdate(ptr, null_pos, null_bit, auto_flags, field_name); |
| 9519 | |||
| 9520 | 3 | case MYSQL_TYPE_TIME: | |
| 9521 | return new (mem_root) | ||
| 9522 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | Field_time(ptr, null_pos, null_bit, auto_flags, field_name); |
| 9523 | 152055 | case MYSQL_TYPE_TIME2: | |
| 9524 | return new (mem_root) Field_timef( | ||
| 9525 | ptr, null_pos, null_bit, auto_flags, field_name, | ||
| 9526 | 152055 | (field_length > MAX_TIME_WIDTH) ? field_length - 1 - MAX_TIME_WIDTH | |
| 9527 |
2/4✓ Branch 0 taken 152055 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 152055 times.
✗ Branch 3 not taken.
|
152055 | : 0); |
| 9528 | 26907 | case MYSQL_TYPE_DATETIME: | |
| 9529 | return new (mem_root) | ||
| 9530 |
2/4✓ Branch 0 taken 26907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26907 times.
✗ Branch 3 not taken.
|
26907 | Field_datetime(ptr, null_pos, null_bit, auto_flags, field_name); |
| 9531 | 358496 | case MYSQL_TYPE_DATETIME2: | |
| 9532 | return new (mem_root) | ||
| 9533 | Field_datetimef(ptr, null_pos, null_bit, auto_flags, field_name, | ||
| 9534 | (field_length > MAX_DATETIME_WIDTH) | ||
| 9535 | 358496 | ? field_length - 1 - MAX_DATETIME_WIDTH | |
| 9536 |
2/4✓ Branch 0 taken 358496 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 358496 times.
✗ Branch 3 not taken.
|
358496 | : 0); |
| 9537 | ✗ | case MYSQL_TYPE_NULL: | |
| 9538 | return new (mem_root) | ||
| 9539 | ✗ | Field_null(ptr, field_length, auto_flags, field_name, field_charset); | |
| 9540 | 14709 | case MYSQL_TYPE_BIT: | |
| 9541 | return treat_bit_as_char | ||
| 9542 |
4/6✓ Branch 0 taken 13406 times.
✓ Branch 1 taken 1303 times.
✓ Branch 2 taken 13406 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1303 times.
✗ Branch 5 not taken.
|
44127 | ? new (mem_root) |
| 9543 | Field_bit_as_char(ptr, field_length, null_pos, null_bit, | ||
| 9544 |
1/2✓ Branch 0 taken 13406 times.
✗ Branch 1 not taken.
|
26812 | auto_flags, field_name) |
| 9545 | : new (mem_root) | ||
| 9546 | Field_bit(ptr, field_length, null_pos, null_bit, bit_ptr, | ||
| 9547 |
1/2✓ Branch 0 taken 1303 times.
✗ Branch 1 not taken.
|
17315 | bit_offset, auto_flags, field_name); |
| 9548 | |||
| 9549 | 6 | case MYSQL_TYPE_INVALID: | |
| 9550 | case MYSQL_TYPE_BOOL: | ||
| 9551 | default: // Impossible (Wrong version) | ||
| 9552 | 6 | break; | |
| 9553 | } | ||
| 9554 | 6 | return nullptr; | |
| 9555 | } | ||
| 9556 | |||
| 9557 | 26269892 | Field *make_field(const Create_field &create_field, TABLE_SHARE *share, | |
| 9558 | const char *field_name, size_t field_length, uchar *ptr, | ||
| 9559 | uchar *null_pos, size_t null_bit) { | ||
| 9560 | 26269896 | return make_field(*THR_MALLOC, share, ptr, field_length, null_pos, null_bit, | |
| 9561 | 26269892 | create_field.sql_type, create_field.charset, | |
| 9562 | 26269892 | create_field.geom_type, create_field.auto_flags, | |
| 9563 | 26269892 | create_field.interval, field_name, create_field.is_nullable, | |
| 9564 | 26269892 | create_field.is_zerofill, create_field.is_unsigned, | |
| 9565 | 26269892 | create_field.decimals, create_field.treat_bit_as_char, | |
| 9566 | 26269892 | create_field.pack_length_override, create_field.m_srid, | |
| 9567 | 52539782 | create_field.is_array); | |
| 9568 | } | ||
| 9569 | |||
| 9570 | 16512318 | Field *make_field(const Create_field &create_field, TABLE_SHARE *share, | |
| 9571 | uchar *ptr, uchar *null_pos, size_t null_bit) { | ||
| 9572 | 16512318 | return make_field(create_field, share, create_field.field_name, | |
| 9573 | create_field.max_display_width_in_bytes(), ptr, null_pos, | ||
| 9574 | 16512334 | null_bit); | |
| 9575 | } | ||
| 9576 | |||
| 9577 | 9578153 | Field *make_field(const Create_field &create_field, TABLE_SHARE *share) { | |
| 9578 | 9578153 | return make_field(create_field, share, create_field.field_name, | |
| 9579 | create_field.max_display_width_in_bytes(), nullptr, nullptr, | ||
| 9580 | 9578159 | 0); | |
| 9581 | } | ||
| 9582 | |||
| 9583 | /** | ||
| 9584 | maximum possible character length for blob. | ||
| 9585 | |||
| 9586 | This method is used in Item_field::set_field to calculate | ||
| 9587 | max_length for Item. | ||
| 9588 | |||
| 9589 | For example: | ||
| 9590 | CREATE TABLE t2 SELECT CONCAT(tinyblob_utf8_column) FROM t1; | ||
| 9591 | must create a "VARCHAR(255) CHARACTER SET utf8" column. | ||
| 9592 | |||
| 9593 | @return | ||
| 9594 | length | ||
| 9595 | */ | ||
| 9596 | |||
| 9597 | 5962313 | uint32 Field_blob::char_length() const noexcept { | |
| 9598 |
4/5✓ Branch 0 taken 50363 times.
✓ Branch 1 taken 2564746 times.
✓ Branch 2 taken 2416916 times.
✓ Branch 3 taken 930292 times.
✗ Branch 4 not taken.
|
5962313 | switch (packlength) { |
| 9599 | 50363 | case 1: | |
| 9600 | 50363 | return 255; | |
| 9601 | 2564746 | case 2: | |
| 9602 | 2564746 | return 65535; | |
| 9603 | 2416916 | case 3: | |
| 9604 | 2416916 | return 16777215; | |
| 9605 | 930292 | case 4: | |
| 9606 | 930292 | return (uint32)4294967295U; | |
| 9607 | ✗ | default: | |
| 9608 | ✗ | assert(0); // we should never go here | |
| 9609 | return 0; | ||
| 9610 | } | ||
| 9611 | } | ||
| 9612 | |||
| 9613 | /** | ||
| 9614 | This function creates a separate copy of blob value. | ||
| 9615 | |||
| 9616 | @param [in] mem_root | ||
| 9617 | mem_root that is used to allocate memory for 'copy_of_value'. | ||
| 9618 | |||
| 9619 | @return - Can fail if we are out of memory. | ||
| 9620 | @retval false Success | ||
| 9621 | @retval true Failure | ||
| 9622 | */ | ||
| 9623 | |||
| 9624 | 1001 | bool Field_blob::copy_blob_value(MEM_ROOT *mem_root) { | |
| 9625 |
1/2✓ Branch 0 taken 1001 times.
✗ Branch 1 not taken.
|
1001 | DBUG_TRACE; |
| 9626 | |||
| 9627 | // Testing memory allocation failure | ||
| 9628 |
2/6✓ Branch 0 taken 1001 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1001 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1001 | DBUG_EXECUTE_IF("simulate_blob_memory_allocation_fail", |
| 9629 | DBUG_SET("+d,simulate_out_of_memory");); | ||
| 9630 | |||
| 9631 | // Allocate new memory location | ||
| 9632 |
1/2✓ Branch 0 taken 1001 times.
✗ Branch 1 not taken.
|
1001 | size_t ulen = get_length(ptr); |
| 9633 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1000 times.
|
1001 | if (ulen == 0) { |
| 9634 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | value.set("", 0, value.charset()); |
| 9635 | } else { | ||
| 9636 | char *blob_value = | ||
| 9637 |
2/4✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1000 times.
✗ Branch 3 not taken.
|
1000 | static_cast<char *>(memdup_root(mem_root, get_blob_data(), ulen)); |
| 9638 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1000 times.
|
1000 | if (blob_value == nullptr) return true; |
| 9639 | |||
| 9640 | // Set 'value' with the duplicated data | ||
| 9641 |
1/2✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
|
1000 | value.set(blob_value, ulen, value.charset()); |
| 9642 | } | ||
| 9643 | |||
| 9644 | // Set ptr of Field for duplicated data | ||
| 9645 |
1/2✓ Branch 0 taken 1001 times.
✗ Branch 1 not taken.
|
1001 | store_ptr_and_length(value.ptr(), ulen); |
| 9646 | |||
| 9647 | 1001 | return false; | |
| 9648 | 1001 | } | |
| 9649 | |||
| 9650 | /** | ||
| 9651 | maximum possible display length for blob. | ||
| 9652 | |||
| 9653 | @return | ||
| 9654 | length | ||
| 9655 | */ | ||
| 9656 | |||
| 9657 | 5663422 | uint32 Field_blob::max_display_length() const { | |
| 9658 |
4/5✓ Branch 0 taken 48039 times.
✓ Branch 1 taken 2341592 times.
✓ Branch 2 taken 2401663 times.
✓ Branch 3 taken 872133 times.
✗ Branch 4 not taken.
|
5663422 | switch (packlength) { |
| 9659 | 48039 | case 1: | |
| 9660 | 48039 | return 255 * field_charset->mbmaxlen; | |
| 9661 | 2341592 | case 2: | |
| 9662 | 2341592 | return 65535 * field_charset->mbmaxlen; | |
| 9663 | 2401663 | case 3: | |
| 9664 | 2401663 | return 16777215 * field_charset->mbmaxlen; | |
| 9665 | 872133 | case 4: | |
| 9666 | 872133 | return (uint32)4294967295U; | |
| 9667 | ✗ | default: | |
| 9668 | ✗ | assert(0); // we should never go here | |
| 9669 | return 0; | ||
| 9670 | } | ||
| 9671 | } | ||
| 9672 | |||
| 9673 | /***************************************************************************** | ||
| 9674 | Warning handling | ||
| 9675 | *****************************************************************************/ | ||
| 9676 | |||
| 9677 | /** | ||
| 9678 | Produce warning or note about data saved into field. | ||
| 9679 | |||
| 9680 | @param level - level of message (Note/Warning/Error) | ||
| 9681 | @param code - error code of message to be produced | ||
| 9682 | @param truncate_increment - whether we should increase truncated fields | ||
| 9683 | count | ||
| 9684 | @param view_db_name - if set this is the database name for view | ||
| 9685 | that causes the warning | ||
| 9686 | @param view_name - if set this is the name of view that causes | ||
| 9687 | the warning | ||
| 9688 | |||
| 9689 | @note | ||
| 9690 | This function won't produce warning and increase cut fields counter | ||
| 9691 | if check_for_truncated_fields == CHECK_FIELD_IGNORE for current thread. | ||
| 9692 | |||
| 9693 | if check_for_truncated_fields == CHECK_FIELD_IGNORE then we ignore notes. | ||
| 9694 | This allows us to avoid notes in optimisation, like convert_constant_item(). | ||
| 9695 | |||
| 9696 | In case of execution statements INSERT/INSERT SELECT/REPLACE/REPLACE SELECT | ||
| 9697 | the method emits only one warning message for the following | ||
| 9698 | types of warning: ER_BAD_NULL_ERROR, ER_WARN_NULL_TO_NOTNULL, | ||
| 9699 | ER_NO_DEFAULT_FOR_FIELD. | ||
| 9700 | @retval | ||
| 9701 | 1 if check_for_truncated_fields == CHECK_FIELD_IGNORE and error level | ||
| 9702 | is not NOTE | ||
| 9703 | @retval | ||
| 9704 | 0 otherwise | ||
| 9705 | */ | ||
| 9706 | |||
| 9707 | 177852 | bool Field::set_warning(Sql_condition::enum_severity_level level, uint code, | |
| 9708 | int truncate_increment, const char *view_db_name, | ||
| 9709 | const char *view_name) { | ||
| 9710 | /* | ||
| 9711 | If this field was created only for type conversion purposes it | ||
| 9712 | will have table == NULL. | ||
| 9713 | */ | ||
| 9714 | |||
| 9715 | 177852 | THD *thd = current_thd; | |
| 9716 | |||
| 9717 |
2/2✓ Branch 0 taken 147367 times.
✓ Branch 1 taken 30485 times.
|
177852 | if (!thd->check_for_truncated_fields) |
| 9718 | 147367 | return level >= Sql_condition::SL_WARNING; | |
| 9719 | |||
| 9720 | 30485 | thd->num_truncated_fields += truncate_increment; | |
| 9721 | |||
| 9722 |
2/2✓ Branch 0 taken 11412 times.
✓ Branch 1 taken 19073 times.
|
30485 | if (thd->lex->sql_command != SQLCOM_INSERT && |
| 9723 |
2/2✓ Branch 0 taken 7479 times.
✓ Branch 1 taken 3933 times.
|
11412 | thd->lex->sql_command != SQLCOM_INSERT_SELECT && |
| 9724 |
2/2✓ Branch 0 taken 7428 times.
✓ Branch 1 taken 51 times.
|
7479 | thd->lex->sql_command != SQLCOM_REPLACE && |
| 9725 |
2/2✓ Branch 0 taken 7312 times.
✓ Branch 1 taken 116 times.
|
7428 | thd->lex->sql_command != SQLCOM_REPLACE_SELECT) { |
| 9726 | // We aggregate warnings from only INSERT and REPLACE statements. | ||
| 9727 | |||
| 9728 | 7312 | push_warning_printf(thd, level, code, ER_THD_NONCONST(thd, code), | |
| 9729 | field_name, | ||
| 9730 | thd->get_stmt_da()->current_row_for_condition()); | ||
| 9731 | |||
| 9732 | 7312 | return false; | |
| 9733 | } | ||
| 9734 | |||
| 9735 | 23173 | unsigned int current_warning_mask = 0; | |
| 9736 | |||
| 9737 |
2/2✓ Branch 0 taken 210 times.
✓ Branch 1 taken 22963 times.
|
23173 | if (code == ER_BAD_NULL_ERROR) |
| 9738 | 210 | current_warning_mask = BAD_NULL_ERROR_PUSHED; | |
| 9739 |
2/2✓ Branch 0 taken 1092 times.
✓ Branch 1 taken 21871 times.
|
22963 | else if (code == ER_NO_DEFAULT_FOR_FIELD) |
| 9740 | 1092 | current_warning_mask = NO_DEFAULT_FOR_FIELD_PUSHED; | |
| 9741 | |||
| 9742 |
2/2✓ Branch 0 taken 1302 times.
✓ Branch 1 taken 21871 times.
|
23173 | if (current_warning_mask) { |
| 9743 |
2/2✓ Branch 0 taken 699 times.
✓ Branch 1 taken 603 times.
|
1302 | if (!(m_warnings_pushed & current_warning_mask)) { |
| 9744 | 699 | push_warning_printf(thd, level, code, ER_THD_NONCONST(thd, code), | |
| 9745 | field_name, | ||
| 9746 | thd->get_stmt_da()->current_row_for_condition()); | ||
| 9747 | 699 | m_warnings_pushed |= current_warning_mask; | |
| 9748 | } | ||
| 9749 |
2/2✓ Branch 0 taken 133 times.
✓ Branch 1 taken 21738 times.
|
21871 | } else if (code == ER_NO_DEFAULT_FOR_VIEW_FIELD) { |
| 9750 |
2/2✓ Branch 0 taken 81 times.
✓ Branch 1 taken 52 times.
|
133 | if (!(m_warnings_pushed & NO_DEFAULT_FOR_VIEW_FIELD_PUSHED)) { |
| 9751 | 81 | push_warning_printf( | |
| 9752 | thd, Sql_condition::SL_WARNING, ER_NO_DEFAULT_FOR_VIEW_FIELD, | ||
| 9753 | ER_THD(thd, ER_NO_DEFAULT_FOR_VIEW_FIELD), view_db_name, view_name); | ||
| 9754 | 81 | m_warnings_pushed |= NO_DEFAULT_FOR_VIEW_FIELD_PUSHED; | |
| 9755 | } | ||
| 9756 | } else { | ||
| 9757 | 21738 | push_warning_printf(thd, level, code, ER_THD_NONCONST(thd, code), | |
| 9758 | field_name, | ||
| 9759 | thd->get_stmt_da()->current_row_for_condition()); | ||
| 9760 | } | ||
| 9761 | |||
| 9762 | 23173 | return false; | |
| 9763 | } | ||
| 9764 | |||
| 9765 | 4339 | bool Field_temporal::set_datetime_warning( | |
| 9766 | Sql_condition::enum_severity_level level, uint code, | ||
| 9767 | const ErrConvString &val, enum_mysql_timestamp_type ts_type, | ||
| 9768 | int truncate_increment) { | ||
| 9769 | 4339 | THD *thd = current_thd; | |
| 9770 | 4339 | if ((!thd->lex->is_ignore() && | |
| 9771 |
2/2✓ Branch 0 taken 2692 times.
✓ Branch 1 taken 174 times.
|
2866 | ((thd->variables.sql_mode & MODE_STRICT_ALL_TABLES) || |
| 9772 |
2/2✓ Branch 0 taken 437 times.
✓ Branch 1 taken 2255 times.
|
2692 | (thd->variables.sql_mode & MODE_STRICT_TRANS_TABLES && |
| 9773 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 434 times.
|
437 | !thd->get_transaction()->cannot_safely_rollback( |
| 9774 |
4/4✓ Branch 0 taken 2866 times.
✓ Branch 1 taken 1473 times.
✓ Branch 2 taken 1111 times.
✓ Branch 3 taken 3228 times.
|
8678 | Transaction_ctx::STMT)))) || |
| 9775 |
2/2✓ Branch 0 taken 503 times.
✓ Branch 1 taken 3228 times.
|
3731 | set_warning(level, code, truncate_increment)) |
| 9776 | 1111 | return make_truncated_value_warning(thd, level, val, ts_type, field_name); | |
| 9777 | |||
| 9778 | 3228 | return false; | |
| 9779 | } | ||
| 9780 | |||
| 9781 | 407 | bool Field::is_part_of_actual_key(THD *thd, uint cur_index, | |
| 9782 | KEY *cur_index_info) const { | ||
| 9783 | 407 | return thd->optimizer_switch_flag(OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS) && | |
| 9784 |
2/2✓ Branch 0 taken 274 times.
✓ Branch 1 taken 117 times.
|
391 | !(cur_index_info->flags & HA_NOSAME) |
| 9785 |
2/2✓ Branch 0 taken 391 times.
✓ Branch 1 taken 16 times.
|
681 | ? part_of_key.is_set(cur_index) |
| 9786 | 407 | : part_of_key_not_extended.is_set(cur_index); | |
| 9787 | } | ||
| 9788 | |||
| 9789 | 1039 | Field_typed_array::Field_typed_array(const Field_typed_array &other) | |
| 9790 | : Field_json(other), | ||
| 9791 | 1039 | m_elt_type(other.m_elt_type), | |
| 9792 | 1039 | m_elt_decimals(other.m_elt_decimals), | |
| 9793 | 1039 | m_elt_charset(other.m_elt_charset), | |
| 9794 | 1039 | unsigned_flag(other.is_unsigned()) {} | |
| 9795 | |||
| 9796 | 2482 | Field_typed_array::Field_typed_array( | |
| 9797 | enum_field_types elt_type, bool elt_is_unsigned, size_t elt_length, | ||
| 9798 | uint elt_decimals, uchar *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg, | ||
| 9799 | uchar auto_flags_arg, const char *field_name_arg, TABLE_SHARE *share, | ||
| 9800 | 2482 | uint blob_pack_length, const CHARSET_INFO *cs) | |
| 9801 | : Field_json(ptr_arg, null_ptr_arg, null_bit_arg, auto_flags_arg, | ||
| 9802 | field_name_arg, share, blob_pack_length), | ||
| 9803 | 2482 | m_elt_type(elt_type), | |
| 9804 | 2482 | m_elt_decimals(elt_decimals), | |
| 9805 | 2482 | m_elt_charset(cs), | |
| 9806 | 2482 | unsigned_flag(elt_is_unsigned) { | |
| 9807 |
2/2✓ Branch 0 taken 666 times.
✓ Branch 1 taken 1816 times.
|
2482 | if (elt_is_unsigned) set_flag(UNSIGNED_FLAG); |
| 9808 |
2/2✓ Branch 0 taken 1974 times.
✓ Branch 1 taken 508 times.
|
2482 | if (Field_typed_array::binary()) set_flag(BINARY_FLAG); |
| 9809 | 2482 | field_length = elt_length; | |
| 9810 | /* | ||
| 9811 | Arrays of BLOB aren't supported and can't be created, so mask the BLOB | ||
| 9812 | flag of JSON | ||
| 9813 | */ | ||
| 9814 | 2482 | clear_flag(BLOB_FLAG); | |
| 9815 |
2/4✓ Branch 0 taken 2482 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2482 times.
✗ Branch 3 not taken.
|
2482 | assert(elt_type != MYSQL_TYPE_STRING && elt_type != MYSQL_TYPE_VAR_STRING); |
| 9816 | 2482 | } | |
| 9817 | |||
| 9818 | 86649 | uint32 Field_typed_array::key_length() const { | |
| 9819 | 86649 | return calc_key_length(m_elt_type, field_length, m_elt_decimals, | |
| 9820 | 86649 | is_unsigned(), | |
| 9821 | // Number of intervals isn't applicable here | ||
| 9822 | 86649 | 0); | |
| 9823 | } | ||
| 9824 | |||
| 9825 | 1039 | Field_typed_array *Field_typed_array::clone(MEM_ROOT *mem_root) const { | |
| 9826 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1039 times.
|
1039 | assert(is_array()); |
| 9827 |
2/4✓ Branch 0 taken 1039 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1039 times.
✗ Branch 3 not taken.
|
1039 | return new (mem_root) Field_typed_array(*this); |
| 9828 | } | ||
| 9829 | |||
| 9830 | 7384 | Item_result Field_typed_array::result_type() const { | |
| 9831 | 7384 | return field_types_result_type[field_type2index(m_elt_type)]; | |
| 9832 | } | ||
| 9833 | |||
| 9834 | ✗ | type_conversion_status Field_typed_array::store(const char *to, size_t length, | |
| 9835 | const CHARSET_INFO *charset) { | ||
| 9836 | ✗ | return m_conv_item->field->store(to, length, charset); | |
| 9837 | } | ||
| 9838 | |||
| 9839 | ✗ | type_conversion_status Field_typed_array::store(double nr) { | |
| 9840 | ✗ | return m_conv_item->field->store(nr); | |
| 9841 | } | ||
| 9842 | |||
| 9843 | ✗ | type_conversion_status Field_typed_array::store(longlong nr, | |
| 9844 | bool unsigned_val) { | ||
| 9845 | ✗ | return m_conv_item->field->store(nr, unsigned_val); | |
| 9846 | } | ||
| 9847 | |||
| 9848 | 28133 | type_conversion_status Field_typed_array::store_array(const Json_wrapper *data, | |
| 9849 | Json_array *array) { | ||
| 9850 | 28133 | array->clear(); | |
| 9851 | |||
| 9852 | 28133 | set_null(); | |
| 9853 | |||
| 9854 | try { | ||
| 9855 | // How to store values | ||
| 9856 |
6/9✓ Branch 0 taken 28133 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 104 times.
✓ Branch 4 taken 28016 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
28133 | switch (data->type()) { |
| 9857 | 11 | case enum_json_type::J_NULL: { | |
| 9858 | /* | ||
| 9859 | Unlike SQL NULL, JSON null is a value, but a special one and it | ||
| 9860 | can't be coerced to any data type. The latter means it can't be | ||
| 9861 | indexed by relational SE. Due to that an error is thrown. | ||
| 9862 | */ | ||
| 9863 |
2/4✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
|
11 | my_error(ER_INVALID_JSON_VALUE_FOR_FUNC_INDEX, MYF(0), |
| 9864 | get_index_name()); | ||
| 9865 | 11 | return TYPE_ERR_BAD_VALUE; | |
| 9866 | } | ||
| 9867 | 104 | case enum_json_type::J_DECIMAL: | |
| 9868 | case enum_json_type::J_DOUBLE: | ||
| 9869 | case enum_json_type::J_STRING: | ||
| 9870 | case enum_json_type::J_DATE: | ||
| 9871 | case enum_json_type::J_TIME: | ||
| 9872 | case enum_json_type::J_DATETIME: | ||
| 9873 | case enum_json_type::J_TIMESTAMP: | ||
| 9874 | case enum_json_type::J_INT: | ||
| 9875 | case enum_json_type::J_UINT: { | ||
| 9876 | // Handle scalars | ||
| 9877 | 104 | Json_wrapper coerced; | |
| 9878 |
3/4✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 101 times.
|
104 | if (coerce_json_value(data, false, &coerced)) |
| 9879 | 3 | return TYPE_ERR_BAD_VALUE; /* purecov: inspected */ | |
| 9880 | 101 | coerced.set_alias(); | |
| 9881 |
3/6✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 101 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 101 times.
|
101 | if (array->append_alias(coerced.to_dom())) { |
| 9882 | ✗ | return TYPE_ERR_OOM; | |
| 9883 | } | ||
| 9884 |
1/2✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
|
101 | Json_wrapper wr(array, true); |
| 9885 | /* | ||
| 9886 | No need to check multi-valued key limits, as single value is always | ||
| 9887 | allowed if engine supports multi-valued index, and single value | ||
| 9888 | can't outgrow index length limit. | ||
| 9889 | */ | ||
| 9890 |
1/2✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
|
101 | set_notnull(); |
| 9891 |
1/2✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
|
101 | return store_json(&wr); |
| 9892 | 104 | } | |
| 9893 | 28016 | case enum_json_type::J_ARRAY: { | |
| 9894 | // Handle array | ||
| 9895 | 28016 | Json_wrapper coerced; | |
| 9896 | 28016 | uint max_num_keys = 0; | |
| 9897 | 28016 | size_t keys_length = 0, max_keys_length = 0; | |
| 9898 | |||
| 9899 | // Empty array stored as non-NULL empty array | ||
| 9900 |
3/4✓ Branch 0 taken 28016 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 27978 times.
|
28016 | if (data->length() == 0) { |
| 9901 |
1/2✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
|
38 | Json_wrapper wr(array, true); |
| 9902 |
1/2✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
|
38 | set_notnull(); |
| 9903 |
1/2✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
|
38 | return store_json(&wr); |
| 9904 | 38 | } | |
| 9905 |
1/2✓ Branch 0 taken 27978 times.
✗ Branch 1 not taken.
|
27978 | table->file->ha_mv_key_capacity(&max_num_keys, &max_keys_length); |
| 9906 |
2/4✓ Branch 0 taken 27978 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27978 times.
✗ Branch 3 not taken.
|
27978 | assert(max_num_keys && max_keys_length); |
| 9907 |
3/4✓ Branch 0 taken 357506 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329554 times.
✓ Branch 3 taken 27952 times.
|
357506 | for (size_t i = 0; i < data->length(); i++) { |
| 9908 |
1/2✓ Branch 0 taken 329554 times.
✗ Branch 1 not taken.
|
329554 | Json_wrapper elt = (*data)[i]; |
| 9909 |
3/4✓ Branch 0 taken 329554 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 329546 times.
|
329554 | if (elt.type() == enum_json_type::J_NULL) { |
| 9910 | /* | ||
| 9911 | Unlike SQL NULL, JSON null is a value, but a special one and it | ||
| 9912 | can't be coerced to any data type. The latter means it can't be | ||
| 9913 | indexed by relational SE. Due to that an error is thrown. | ||
| 9914 | */ | ||
| 9915 |
2/4✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
8 | my_error(ER_INVALID_JSON_VALUE_FOR_FUNC_INDEX, MYF(0), |
| 9916 | get_index_name()); | ||
| 9917 | 8 | return TYPE_ERR_BAD_VALUE; | |
| 9918 | } | ||
| 9919 | |||
| 9920 |
3/4✓ Branch 0 taken 329546 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 329528 times.
|
329546 | if (coerce_json_value(&elt, false, &coerced)) |
| 9921 | 18 | return TYPE_ERR_BAD_VALUE; | |
| 9922 | 329528 | coerced.set_alias(); | |
| 9923 |
3/6✓ Branch 0 taken 329528 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329528 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 329528 times.
|
329528 | if (array->append_alias(coerced.to_dom())) { |
| 9924 | ✗ | return TYPE_ERR_OOM; | |
| 9925 | } | ||
| 9926 |
2/2✓ Branch 0 taken 69211 times.
✓ Branch 1 taken 260317 times.
|
329528 | if (type() == MYSQL_TYPE_VARCHAR) |
| 9927 |
1/2✓ Branch 0 taken 69211 times.
✗ Branch 1 not taken.
|
69211 | keys_length += coerced.get_data_length(); |
| 9928 | else | ||
| 9929 |
1/2✓ Branch 0 taken 260317 times.
✗ Branch 1 not taken.
|
260317 | keys_length += m_conv_item->field->pack_length(); |
| 9930 |
2/2✓ Branch 0 taken 329528 times.
✓ Branch 1 taken 26 times.
|
329554 | } |
| 9931 | /* | ||
| 9932 | Non-strict mode issue: | ||
| 9933 | While consisting of unique values, bad input can cause duplicates | ||
| 9934 | after coercion. Remove them, as SE doesn't expect dups in the array. | ||
| 9935 | This is why we need to sort & remove duplicates only after | ||
| 9936 | processing all keys. | ||
| 9937 | */ | ||
| 9938 |
2/2✓ Branch 0 taken 27565 times.
✓ Branch 1 taken 387 times.
|
27952 | if (array->size() > 1) |
| 9939 |
3/4✓ Branch 0 taken 603 times.
✓ Branch 1 taken 26962 times.
✓ Branch 2 taken 27565 times.
✗ Branch 3 not taken.
|
27565 | array->remove_duplicates(type() == MYSQL_TYPE_VARCHAR ? m_elt_charset |
| 9940 | : nullptr); | ||
| 9941 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 27950 times.
|
27952 | if (array->size() > max_num_keys) { |
| 9942 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | my_error(ER_EXCEEDED_MV_KEYS_NUM, MYF(0), get_index_name(), |
| 9943 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | array->size() - max_num_keys); |
| 9944 | 2 | return TYPE_ERR_BAD_VALUE; | |
| 9945 | } | ||
| 9946 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 27949 times.
|
27950 | if (keys_length > max_keys_length) { |
| 9947 | // Array fields have only one index defined over them | ||
| 9948 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | my_error(ER_EXCEEDED_MV_KEYS_SPACE, MYF(0), get_index_name(), |
| 9949 | (keys_length - max_keys_length)); | ||
| 9950 | 1 | return TYPE_ERR_BAD_VALUE; | |
| 9951 | } | ||
| 9952 |
1/2✓ Branch 0 taken 27949 times.
✗ Branch 1 not taken.
|
27949 | Json_wrapper wr(array, true); |
| 9953 |
1/2✓ Branch 0 taken 27949 times.
✗ Branch 1 not taken.
|
27949 | set_notnull(); |
| 9954 |
1/2✓ Branch 0 taken 27949 times.
✗ Branch 1 not taken.
|
27949 | return store_json(&wr); |
| 9955 | 28016 | } | |
| 9956 | 1 | case enum_json_type::J_BOOLEAN: { | |
| 9957 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | my_error(ER_NOT_SUPPORTED_YET, MYF(0), |
| 9958 | "CAST-ing JSON BOOLEAN type to array"); | ||
| 9959 | 1 | return TYPE_ERR_BAD_VALUE; | |
| 9960 | } | ||
| 9961 | |||
| 9962 | 1 | case enum_json_type::J_OBJECT: { | |
| 9963 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | my_error(ER_NOT_SUPPORTED_YET, MYF(0), |
| 9964 | "CAST-ing JSON OBJECT type to array"); | ||
| 9965 | 1 | return TYPE_ERR_BAD_VALUE; | |
| 9966 | } | ||
| 9967 | ✗ | case enum_json_type::J_ERROR: | |
| 9968 | ✗ | my_error(ER_INVALID_JSON_VALUE_FOR_FUNC_INDEX, MYF(0), | |
| 9969 | get_index_name()); | ||
| 9970 | ✗ | return TYPE_ERR_BAD_VALUE; | |
| 9971 | /* purecov: begin inspected */ | ||
| 9972 | ✗ | default: | |
| 9973 | // Shouldn't happen | ||
| 9974 | ✗ | assert(0); | |
| 9975 | return TYPE_ERR_BAD_VALUE; | ||
| 9976 | } | ||
| 9977 | ✗ | } catch (...) { | |
| 9978 | ✗ | handle_std_exception("typed array field"); | |
| 9979 | } | ||
| 9980 | ✗ | return TYPE_ERR_BAD_VALUE; | |
| 9981 | /* purecov: end */ | ||
| 9982 | } | ||
| 9983 | |||
| 9984 | 761 | size_t Field_typed_array::get_key_image(uchar *buff, size_t length, | |
| 9985 | imagetype type) const { | ||
| 9986 | 761 | return m_conv_item->field->get_key_image(buff, length, type); | |
| 9987 | } | ||
| 9988 | |||
| 9989 | 35 | Field *Field_typed_array::get_conv_field() { return m_conv_item->field; } | |
| 9990 | |||
| 9991 | 374 | Field *Field_typed_array::new_key_field(MEM_ROOT *root, TABLE *new_table, | |
| 9992 | uchar *new_ptr, uchar *, uint) const { | ||
| 9993 | 374 | Field *res = m_conv_item->field->new_key_field(root, new_table, new_ptr); | |
| 9994 |
1/2✓ Branch 0 taken 374 times.
✗ Branch 1 not taken.
|
374 | if (res != nullptr) { |
| 9995 | // Keep the field hidden to allow error handler to catch functional | ||
| 9996 | // index's errors | ||
| 9997 | 374 | res->set_hidden(dd::Column::enum_hidden_type::HT_HIDDEN_SQL); | |
| 9998 | 374 | res->part_of_key = part_of_key; | |
| 9999 | } | ||
| 10000 | 374 | return res; | |
| 10001 | } | ||
| 10002 | |||
| 10003 | 2556 | void Field_typed_array::init(TABLE *table_arg) { | |
| 10004 |
1/2✓ Branch 0 taken 2556 times.
✗ Branch 1 not taken.
|
2556 | Field::init(table_arg); |
| 10005 | |||
| 10006 |
1/2✓ Branch 0 taken 2556 times.
✗ Branch 1 not taken.
|
2556 | switch (type()) { |
| 10007 | 2556 | case MYSQL_TYPE_VARCHAR: | |
| 10008 | case MYSQL_TYPE_TIME: | ||
| 10009 | case MYSQL_TYPE_DATETIME: | ||
| 10010 | case MYSQL_TYPE_TIMESTAMP: | ||
| 10011 | case MYSQL_TYPE_DATE: | ||
| 10012 | case MYSQL_TYPE_LONG: | ||
| 10013 | case MYSQL_TYPE_LONGLONG: | ||
| 10014 | case MYSQL_TYPE_NEWDECIMAL: | ||
| 10015 | 2556 | break; | |
| 10016 | ✗ | case MYSQL_TYPE_YEAR: | |
| 10017 | default: | ||
| 10018 | // Shouldn't happen | ||
| 10019 | ✗ | assert(0); /* purecov: inspected */ | |
| 10020 | return; | ||
| 10021 | } | ||
| 10022 | |||
| 10023 | // Set mem_root for conversion field allocation. | ||
| 10024 | 2556 | MEM_ROOT *actual_mem_root = | |
| 10025 | 2556 | (table_arg->s->table_category == TABLE_CATEGORY_TEMPORARY) | |
| 10026 |
2/2✓ Branch 0 taken 266 times.
✓ Branch 1 taken 2290 times.
|
2556 | ? &table_arg->s->mem_root |
| 10027 | : &table_arg->mem_root; | ||
| 10028 | // Create field for data conversion | ||
| 10029 | 5112 | Field *conv_field = ::make_field( | |
| 10030 | // Allocate conversion field in table's mem_root for non-temp | ||
| 10031 | // tables. Allocate conversion field in TABLE_SHARE's mem_root | ||
| 10032 | // for internal temporary tables. | ||
| 10033 | actual_mem_root, | ||
| 10034 | nullptr, // TABLE_SHARE, not needed | ||
| 10035 | nullptr, // data buffer, isn't allocated yet | ||
| 10036 |
1/2✓ Branch 0 taken 2556 times.
✗ Branch 1 not taken.
|
2556 | field_length, // field_length |
| 10037 | nullptr, 0, // null_pos, nul_bit | ||
| 10038 | real_type(), // field_type | ||
| 10039 | m_elt_charset, | ||
| 10040 | Field::GEOM_GEOMETRY, // geom type | ||
| 10041 | Field::NONE, // auto_flags | ||
| 10042 | nullptr, // intervals aren't supported in array | ||
| 10043 | 2556 | field_name, is_nullable(), | |
| 10044 | false, // zerofill is meaningless with JSON | ||
| 10045 | 2556 | is_unsigned(), m_elt_decimals, | |
| 10046 | false, // treat_bit_as_char | ||
| 10047 | 0, // pack_length_override | ||
| 10048 | {}, // srid | ||
| 10049 | false // is_array | ||
| 10050 | ); | ||
| 10051 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2556 times.
|
2556 | if (conv_field == nullptr) return; |
| 10052 | uchar *buf = | ||
| 10053 |
2/4✓ Branch 0 taken 2556 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2556 times.
✗ Branch 3 not taken.
|
2556 | actual_mem_root->ArrayAlloc<uchar>(conv_field->pack_length() + 1); |
| 10054 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2556 times.
|
2556 | if (buf == nullptr) return; |
| 10055 |
2/2✓ Branch 0 taken 282 times.
✓ Branch 1 taken 2274 times.
|
2556 | if (type() == MYSQL_TYPE_NEWDECIMAL) |
| 10056 | 282 | (down_cast<Field_new_decimal *>(conv_field))->set_keep_precision(true); | |
| 10057 | 2556 | conv_field->move_field(buf + 1, buf, 0); | |
| 10058 | 2556 | conv_field->table = table; | |
| 10059 | 2556 | conv_field->table_name = table_name; | |
| 10060 |
1/2✓ Branch 0 taken 2556 times.
✗ Branch 1 not taken.
|
2556 | conv_field->set_field_index(field_index()); |
| 10061 | |||
| 10062 | // Swap arena so that the Item_field is allocated on TABLE::mem_root for | ||
| 10063 | // non-temp tables and so it does not end up in THD's item list which will | ||
| 10064 | // have a different lifetime than TABLE::mem_root | ||
| 10065 | 5112 | Query_arena tmp_arena(actual_mem_root, Query_arena::STMT_REGULAR_EXECUTION); | |
| 10066 | 5112 | Query_arena backup_arena; | |
| 10067 |
2/4✓ Branch 0 taken 2556 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2556 times.
✗ Branch 3 not taken.
|
2556 | current_thd->swap_query_arena(tmp_arena, &backup_arena); |
| 10068 |
2/4✓ Branch 0 taken 2556 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2556 times.
✗ Branch 3 not taken.
|
2556 | m_conv_item = new Item_field(conv_field); |
| 10069 |
2/4✓ Branch 0 taken 2556 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2556 times.
✗ Branch 3 not taken.
|
2556 | current_thd->swap_query_arena(backup_arena, &tmp_arena); |
| 10070 | } | ||
| 10071 | |||
| 10072 | 22 | const char *Field_typed_array::get_index_name() const { | |
| 10073 | 22 | uint key = part_of_key.get_first_set(); | |
| 10074 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
|
22 | assert(key != MY_BIT_NONE); |
| 10075 | 22 | return table->s->key_info[key].name; | |
| 10076 | } | ||
| 10077 | |||
| 10078 | 113 | size_t Field_typed_array::make_sort_key(Json_wrapper *wr, uchar *to, | |
| 10079 | size_t length) const { | ||
| 10080 | #ifndef NDEBUG | ||
| 10081 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 113 times.
|
113 | switch (wr->type()) { |
| 10082 | ✗ | case enum_json_type::J_ERROR: | |
| 10083 | case enum_json_type::J_OBJECT: | ||
| 10084 | case enum_json_type::J_ARRAY: | ||
| 10085 | // Only scalars are supported | ||
| 10086 | ✗ | assert(false); | |
| 10087 | break; | ||
| 10088 | 113 | default: | |
| 10089 | 113 | break; | |
| 10090 | } | ||
| 10091 | #endif | ||
| 10092 | 113 | THD *thd = current_thd; | |
| 10093 | // Force error on bad data | ||
| 10094 | #ifndef NDEBUG | ||
| 10095 | bool res = | ||
| 10096 | #endif | ||
| 10097 | 113 | save_json_to_field(thd, m_conv_item->field, wr, true); | |
| 10098 | // Data should be already properly converted so no error is expected here | ||
| 10099 |
2/4✓ Branch 0 taken 113 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 113 times.
✗ Branch 3 not taken.
|
113 | assert(!res && !thd->is_error()); |
| 10100 | |||
| 10101 | 113 | return m_conv_item->field->make_sort_key(to, length); | |
| 10102 | } | ||
| 10103 | |||
| 10104 | ✗ | int Field_typed_array::do_save_field_metadata(uchar *metadata_ptr) const { | |
| 10105 | ✗ | *metadata_ptr = static_cast<uchar>(m_elt_type); | |
| 10106 | ✗ | switch (m_elt_type) { | |
| 10107 | ✗ | case MYSQL_TYPE_VARCHAR: { | |
| 10108 | ✗ | assert(field_length < 65536); | |
| 10109 | ✗ | char *param_ptr = (char *)(metadata_ptr + 1); | |
| 10110 | ✗ | int3store(param_ptr, field_length); | |
| 10111 | ✗ | return 4; | |
| 10112 | } | ||
| 10113 | ✗ | case MYSQL_TYPE_NEWDECIMAL: { | |
| 10114 | ✗ | assert(field_length < 128); | |
| 10115 | ✗ | uint8 precision = my_decimal_length_to_precision(field_length, decimals(), | |
| 10116 | ✗ | is_unsigned()); | |
| 10117 | ✗ | *(metadata_ptr + 1) = precision; | |
| 10118 | ✗ | *(metadata_ptr + 2) = decimals(); | |
| 10119 | ✗ | return 3; | |
| 10120 | } | ||
| 10121 | ✗ | case MYSQL_TYPE_LONGLONG: | |
| 10122 | case MYSQL_TYPE_NEWDATE: | ||
| 10123 | ✗ | return 1; | |
| 10124 | ✗ | case MYSQL_TYPE_TIME2: | |
| 10125 | case MYSQL_TYPE_DATETIME2: | ||
| 10126 | ✗ | *(metadata_ptr + 1) = decimals(); | |
| 10127 | ✗ | return 2; | |
| 10128 | ✗ | case MYSQL_TYPE_YEAR: | |
| 10129 | default: | ||
| 10130 | ✗ | break; | |
| 10131 | } | ||
| 10132 | ✗ | assert(0); // Shouldn't happen | |
| 10133 | return 0; | ||
| 10134 | } | ||
| 10135 | |||
| 10136 | 418 | void Field_typed_array::sql_type(String &str) const { | |
| 10137 | 418 | const Field *const conv_field = m_conv_item->field; | |
| 10138 | // There is no need to append the character set and collation to the type, | ||
| 10139 | // since utf8mb4_0900_bin is the only collation supported for arrays. | ||
| 10140 |
3/4✓ Branch 0 taken 86 times.
✓ Branch 1 taken 332 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 86 times.
|
418 | assert(!conv_field->has_charset() || |
| 10141 | conv_field->charset() == &my_charset_utf8mb4_0900_bin); | ||
| 10142 | 418 | conv_field->sql_type(str); | |
| 10143 | 418 | str.append(STRING_WITH_LEN(" array")); | |
| 10144 | 418 | } | |
| 10145 | |||
| 10146 | 1 | void Field_typed_array::make_send_field(Send_field *field) const { | |
| 10147 | 1 | Field_json::make_send_field(field); | |
| 10148 | // When sending the array to the client (only possible using the debug flag | ||
| 10149 | // show_hidden_columns), it should be sent as a JSON array. Set the type to | ||
| 10150 | // JSON instead of the array element type. | ||
| 10151 | 1 | field->type = MYSQL_TYPE_JSON; | |
| 10152 | 1 | } | |
| 10153 | |||
| 10154 | 965 | void Field_typed_array::set_field_index(uint16 field_index) { | |
| 10155 | 965 | Field::set_field_index(field_index); | |
| 10156 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 965 times.
|
965 | if (m_conv_item) m_conv_item->field->set_field_index(field_index); |
| 10157 | 965 | } | |
| 10158 | |||
| 10159 | 343100 | Key_map Field::get_covering_prefix_keys() const { | |
| 10160 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 343100 times.
|
343100 | if (table == nullptr) { |
| 10161 | // This function might be called when creating functional indexes. In those | ||
| 10162 | // cases, we do not have a table object available. Assert that the function | ||
| 10163 | // is indeed called in a functional index context, and then return an empty | ||
| 10164 | // key map. | ||
| 10165 | ✗ | assert(down_cast<const Create_field_wrapper *>(this) != nullptr); | |
| 10166 | ✗ | return Key_map(); | |
| 10167 | } | ||
| 10168 | 343100 | Key_map covering_prefix_keys = part_of_prefixkey; | |
| 10169 | 343100 | covering_prefix_keys.intersect(table->covering_keys); | |
| 10170 | 343100 | return covering_prefix_keys; | |
| 10171 | } | ||
| 10172 | |||
| 10173 | 273882 | void Field::set_default() { | |
| 10174 |
6/6✓ Branch 0 taken 270098 times.
✓ Branch 1 taken 3784 times.
✓ Branch 2 taken 253 times.
✓ Branch 3 taken 269845 times.
✓ Branch 4 taken 4037 times.
✓ Branch 5 taken 269845 times.
|
543980 | if (has_insert_default_datetime_value_expression() || |
| 10175 | 270098 | has_insert_default_general_value_expression()) | |
| 10176 | 4037 | evaluate_insert_default_function(); | |
| 10177 | else | ||
| 10178 | 269845 | copy_data(table->default_values_offset()); | |
| 10179 | 273882 | } | |
| 10180 | |||
| 10181 | 1038784947 | uint Field::null_offset() const { return null_offset(table->record[0]); } | |
| 10182 | |||
| 10183 | 86041087 | void Field::init(TABLE *table_arg) { | |
| 10184 | 86041087 | table = table_arg; | |
| 10185 | 86041087 | table_name = &table_arg->alias; | |
| 10186 | 86041087 | } | |
| 10187 | |||
| 10188 | // Byteswaps and/or truncates int16 values; used for both pack() and unpack(). | ||
| 10189 | 198279 | static inline void handle_int16(uchar *to, const uchar *from, size_t max_length, | |
| 10190 | bool low_byte_first_from, | ||
| 10191 | bool low_byte_first_to) { | ||
| 10192 | int16 val; | ||
| 10193 | uchar buf[sizeof(val)]; | ||
| 10194 |
1/2✓ Branch 0 taken 198279 times.
✗ Branch 1 not taken.
|
198279 | if (low_byte_first_from) |
| 10195 | 198279 | val = sint2korr(from); | |
| 10196 | else | ||
| 10197 | ✗ | val = shortget(from); | |
| 10198 | |||
| 10199 |
1/2✓ Branch 0 taken 198279 times.
✗ Branch 1 not taken.
|
198279 | if (low_byte_first_to) |
| 10200 | 198279 | int2store(buf, val); | |
| 10201 | else | ||
| 10202 | ✗ | shortstore(buf, val); | |
| 10203 |
1/2✓ Branch 0 taken 198279 times.
✗ Branch 1 not taken.
|
198279 | if (max_length >= sizeof(buf)) { |
| 10204 | // Common case. | ||
| 10205 | 198279 | memcpy(to, buf, sizeof(buf)); | |
| 10206 | } else { | ||
| 10207 | ✗ | memcpy(to, buf, max_length); | |
| 10208 | } | ||
| 10209 | 198279 | } | |
| 10210 | |||
| 10211 | // Byteswaps and/or truncates int24 values; used for both pack() and unpack(). | ||
| 10212 | ✗ | static inline void handle_int24(uchar *to, const uchar *from, size_t max_length, | |
| 10213 | bool low_byte_first_from [[maybe_unused]], | ||
| 10214 | bool low_byte_first_to [[maybe_unused]]) { | ||
| 10215 | int32 val; | ||
| 10216 | uchar buf[3]; | ||
| 10217 | #ifdef WORDS_BIGENDIAN | ||
| 10218 | if (low_byte_first_from) | ||
| 10219 | val = sint3korr(from); | ||
| 10220 | else | ||
| 10221 | #endif | ||
| 10222 | ✗ | val = (from[0] << 16) + (from[1] << 8) + from[2]; | |
| 10223 | |||
| 10224 | #ifdef WORDS_BIGENDIAN | ||
| 10225 | if (low_byte_first_to) | ||
| 10226 | int3store(buf, val); | ||
| 10227 | else | ||
| 10228 | #endif | ||
| 10229 | { | ||
| 10230 | ✗ | buf[0] = 0xFF & (val >> 16); | |
| 10231 | ✗ | buf[1] = 0xFF & (val >> 8); | |
| 10232 | ✗ | buf[2] = 0xFF & val; | |
| 10233 | } | ||
| 10234 | ✗ | if (max_length >= sizeof(buf)) { | |
| 10235 | // Common case. | ||
| 10236 | ✗ | memcpy(to, buf, sizeof(buf)); | |
| 10237 | } else { | ||
| 10238 | ✗ | memcpy(to, buf, max_length); | |
| 10239 | } | ||
| 10240 | } | ||
| 10241 | |||
| 10242 | // Byteswaps and/or truncates int32 values; used for both pack() and unpack(). | ||
| 10243 | 356367242 | static inline void handle_int32(uchar *to, const uchar *from, size_t max_length, | |
| 10244 | bool low_byte_first_from, | ||
| 10245 | bool low_byte_first_to) { | ||
| 10246 | int32 val; | ||
| 10247 | uchar buf[sizeof(val)]; | ||
| 10248 |
1/2✓ Branch 0 taken 356370250 times.
✗ Branch 1 not taken.
|
356367242 | if (low_byte_first_from) |
| 10249 | 356370250 | val = sint4korr(from); | |
| 10250 | else | ||
| 10251 | ✗ | val = longget(from); | |
| 10252 | |||
| 10253 |
1/2✓ Branch 0 taken 356385304 times.
✗ Branch 1 not taken.
|
356385304 | if (low_byte_first_to) |
| 10254 | 356385304 | int4store(buf, val); | |
| 10255 | else | ||
| 10256 | ✗ | longstore(buf, val); | |
| 10257 |
2/2✓ Branch 0 taken 356398489 times.
✓ Branch 1 taken 342 times.
|
356398831 | if (max_length >= sizeof(buf)) { |
| 10258 | // Common case. | ||
| 10259 | 356398489 | memcpy(to, buf, sizeof(buf)); | |
| 10260 | } else { | ||
| 10261 | 342 | memcpy(to, buf, max_length); | |
| 10262 | } | ||
| 10263 | 356398831 | } | |
| 10264 | |||
| 10265 | // Byteswaps and/or truncates int64 values; used for both pack() and unpack(). | ||
| 10266 | 172149722 | static inline void handle_int64(uchar *to, const uchar *from, size_t max_length, | |
| 10267 | bool low_byte_first_from [[maybe_unused]], | ||
| 10268 | bool low_byte_first_to [[maybe_unused]]) { | ||
| 10269 | int64 val; | ||
| 10270 | uchar buf[sizeof(val)]; | ||
| 10271 | #ifdef WORDS_BIGENDIAN | ||
| 10272 | if (low_byte_first_from) | ||
| 10273 | val = sint8korr(from); | ||
| 10274 | else | ||
| 10275 | #endif | ||
| 10276 | 172149722 | memcpy(&val, from, sizeof(val)); | |
| 10277 | |||
| 10278 | #ifdef WORDS_BIGENDIAN | ||
| 10279 | if (low_byte_first_to) | ||
| 10280 | int8store(buf, val); | ||
| 10281 | else | ||
| 10282 | #endif | ||
| 10283 | 172149722 | longlongstore(buf, val); | |
| 10284 |
1/2✓ Branch 0 taken 172149885 times.
✗ Branch 1 not taken.
|
172149827 | if (max_length >= sizeof(buf)) { |
| 10285 | // Common case. | ||
| 10286 | 172149885 | memcpy(to, buf, sizeof(buf)); | |
| 10287 | } else { | ||
| 10288 | ✗ | memcpy(to, buf, max_length); | |
| 10289 | } | ||
| 10290 | 172149827 | } | |
| 10291 | |||
| 10292 | 155249 | uchar *Field::pack_int16(uchar *to, const uchar *from, | |
| 10293 | size_t max_length) const { | ||
| 10294 | 155249 | handle_int16(to, from, max_length, table->s->db_low_byte_first, true); | |
| 10295 | 155249 | return to + sizeof(int16); | |
| 10296 | } | ||
| 10297 | |||
| 10298 | 43030 | const uchar *Field::unpack_int16(uchar *to, const uchar *from) const { | |
| 10299 | 43030 | handle_int16(to, from, UINT_MAX, true, table->s->db_low_byte_first); | |
| 10300 | 43030 | return from + sizeof(int16); | |
| 10301 | } | ||
| 10302 | |||
| 10303 | ✗ | uchar *Field::pack_int24(uchar *to, const uchar *from, | |
| 10304 | size_t max_length) const { | ||
| 10305 | ✗ | handle_int24(to, from, max_length, table->s->db_low_byte_first, true); | |
| 10306 | ✗ | return to + 3; | |
| 10307 | } | ||
| 10308 | |||
| 10309 | ✗ | const uchar *Field::unpack_int24(uchar *to, const uchar *from) const { | |
| 10310 | ✗ | handle_int24(to, from, UINT_MAX, true, table->s->db_low_byte_first); | |
| 10311 | ✗ | return from + 3; | |
| 10312 | } | ||
| 10313 | |||
| 10314 | 121786715 | uchar *Field::pack_int32(uchar *to, const uchar *from, | |
| 10315 | size_t max_length) const { | ||
| 10316 | 121786715 | handle_int32(to, from, max_length, table->s->db_low_byte_first, true); | |
| 10317 | 121826380 | return to + sizeof(int32); | |
| 10318 | } | ||
| 10319 | |||
| 10320 | 234575713 | const uchar *Field::unpack_int32(uchar *to, const uchar *from) const { | |
| 10321 | 234575713 | handle_int32(to, from, UINT_MAX, true, table->s->db_low_byte_first); | |
| 10322 | 234575816 | return from + sizeof(int32); | |
| 10323 | } | ||
| 10324 | |||
| 10325 | 50455224 | uchar *Field::pack_int64(uchar *to, const uchar *from, | |
| 10326 | size_t max_length) const { | ||
| 10327 | 50455224 | handle_int64(to, from, max_length, table->s->db_low_byte_first, true); | |
| 10328 | 50455500 | return to + sizeof(int64); | |
| 10329 | } | ||
| 10330 | |||
| 10331 | 121694434 | const uchar *Field::unpack_int64(uchar *to, const uchar *from) const { | |
| 10332 | 121694434 | handle_int64(to, from, UINT_MAX, true, table->s->db_low_byte_first); | |
| 10333 | 121694434 | return from + sizeof(int64); | |
| 10334 | } | ||
| 10335 | |||
| 10336 | 9622 | bool Field_longstr::is_updatable() const { | |
| 10337 |
2/4✓ Branch 0 taken 9622 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9622 times.
✗ Branch 3 not taken.
|
9622 | assert(table && table->write_set); |
| 10338 | 9622 | return bitmap_is_set(table->write_set, field_index()); | |
| 10339 | } | ||
| 10340 | |||
| 10341 | 10013963 | Field_varstring::Field_varstring(uchar *ptr_arg, uint32 len_arg, | |
| 10342 | uint length_bytes_arg, uchar *null_ptr_arg, | ||
| 10343 | uchar null_bit_arg, uchar auto_flags_arg, | ||
| 10344 | const char *field_name_arg, TABLE_SHARE *share, | ||
| 10345 | 10013963 | const CHARSET_INFO *cs) | |
| 10346 | : Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, | ||
| 10347 | auto_flags_arg, field_name_arg, cs), | ||
| 10348 | 10013963 | length_bytes(length_bytes_arg) { | |
| 10349 |
2/2✓ Branch 0 taken 10013157 times.
✓ Branch 1 taken 808 times.
|
10013965 | if (share != nullptr) { |
| 10350 | 10013157 | share->varchar_fields++; | |
| 10351 | } | ||
| 10352 | 10013965 | } | |
| 10353 | |||
| 10354 | 2906407 | Field_varstring::Field_varstring(uint32 len_arg, bool is_nullable_arg, | |
| 10355 | const char *field_name_arg, TABLE_SHARE *share, | ||
| 10356 | 2906407 | const CHARSET_INFO *cs) | |
| 10357 | : Field_longstr(nullptr, len_arg, | ||
| 10358 | is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE, | ||
| 10359 | field_name_arg, cs), | ||
| 10360 |
4/4✓ Branch 0 taken 1697907 times.
✓ Branch 1 taken 1208500 times.
✓ Branch 2 taken 2249418 times.
✓ Branch 3 taken 656989 times.
|
2906407 | length_bytes(len_arg < 256 ? 1 : 2) { |
| 10361 |
2/2✓ Branch 0 taken 2906341 times.
✓ Branch 1 taken 66 times.
|
2906407 | if (share != nullptr) { |
| 10362 | 2906341 | share->varchar_fields++; | |
| 10363 | } | ||
| 10364 | 2906407 | } | |
| 10365 | |||
| 10366 | 84629970 | void Field_blob::store_length(uchar *i_ptr, uint i_packlength, | |
| 10367 | uint32 i_number) { | ||
| 10368 | 84629970 | store_blob_length(i_ptr, i_packlength, i_number); | |
| 10369 | 84630267 | } | |
| 10370 | |||
| 10371 | 4790291 | uint32 Field_blob::get_length(ptrdiff_t row_offset) const { | |
| 10372 | 4790291 | return get_length(ptr + row_offset, this->packlength); | |
| 10373 | } | ||
| 10374 | |||
| 10375 | 280680041 | uint32 Field_blob::get_length(const uchar *ptr_arg) const { | |
| 10376 | 280680041 | return get_length(ptr_arg, this->packlength); | |
| 10377 | } | ||
| 10378 | |||
| 10379 | 25421 | bool Field_blob::backup_blob_field() { | |
| 10380 | 25421 | value.swap(m_blob_backup); | |
| 10381 | #ifndef NDEBUG | ||
| 10382 | 25421 | m_uses_backup = true; | |
| 10383 | #endif | ||
| 10384 | 25421 | return false; | |
| 10385 | } | ||
| 10386 | |||
| 10387 | 25421 | void Field_blob::restore_blob_backup() { | |
| 10388 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25421 times.
|
25421 | assert(m_uses_backup); |
| 10389 | 25421 | value.swap(m_blob_backup); | |
| 10390 | #ifndef NDEBUG | ||
| 10391 | 25421 | m_uses_backup = false; | |
| 10392 | #endif | ||
| 10393 | 25421 | } | |
| 10394 | |||
| 10395 | 628 | Create_field_wrapper::Create_field_wrapper(const Create_field *fld) | |
| 10396 | 1256 | : Field(nullptr, fld->max_display_width_in_codepoints(), nullptr, 0, | |
| 10397 | 628 | fld->auto_flags, fld->field_name), | |
| 10398 | 628 | m_field(fld) { | |
| 10399 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 625 times.
|
628 | if (fld->is_unsigned) { |
| 10400 | 3 | set_flag(UNSIGNED_FLAG); | |
| 10401 | } | ||
| 10402 | 628 | } | |
| 10403 | |||
| 10404 | 1086 | Item_result Create_field_wrapper::result_type() const { | |
| 10405 | 1086 | return field_types_result_type[field_type2index(m_field->sql_type)]; | |
| 10406 | } | ||
| 10407 | |||
| 10408 | 218 | Item_result Create_field_wrapper::numeric_context_result_type() const { | |
| 10409 | 218 | return ::numeric_context_result_type(type(), result_type(), | |
| 10410 | 436 | m_field->decimals); | |
| 10411 | } | ||
| 10412 | |||
| 10413 | 219 | enum_field_types Create_field_wrapper::type() const { | |
| 10414 | 219 | return m_field->sql_type; | |
| 10415 | } | ||
| 10416 | |||
| 10417 | ✗ | const CHARSET_INFO *Create_field_wrapper::charset() const { | |
| 10418 | ✗ | return m_field->charset; | |
| 10419 | } | ||
| 10420 | |||
| 10421 | ✗ | uint32 Create_field_wrapper::pack_length() const { | |
| 10422 | ✗ | return m_field->pack_length(); | |
| 10423 | } | ||
| 10424 | |||
| 10425 | ✗ | uint32 Create_field_wrapper::max_display_length() const { | |
| 10426 | ✗ | return m_field->max_display_width_in_codepoints(); | |
| 10427 | } | ||
| 10428 | |||
| 10429 | 53129 | Create_field *generate_create_field(THD *thd, Item *item, TABLE *tmp_table) { | |
| 10430 | Field *tmp_table_field; | ||
| 10431 |
2/2✓ Branch 0 taken 5494 times.
✓ Branch 1 taken 47635 times.
|
53129 | if (item->type() == Item::FUNC_ITEM) { |
| 10432 | /* | ||
| 10433 | If the function returns an array, use the method provided by the function | ||
| 10434 | to create the tmp table field, as the generic | ||
| 10435 | tmp_table_field_from_field_type() can't handle typed arrays. | ||
| 10436 | */ | ||
| 10437 |
6/6✓ Branch 0 taken 2702 times.
✓ Branch 1 taken 2792 times.
✓ Branch 2 taken 131 times.
✓ Branch 3 taken 2571 times.
✓ Branch 4 taken 2923 times.
✓ Branch 5 taken 2571 times.
|
5494 | if (item->result_type() != STRING_RESULT || item->returns_array()) |
| 10438 | 2923 | tmp_table_field = item->tmp_table_field(tmp_table); | |
| 10439 | else | ||
| 10440 | 2571 | tmp_table_field = item->tmp_table_field_from_field_type(tmp_table, false); | |
| 10441 | } else { | ||
| 10442 | Field *from_field, *default_field; | ||
| 10443 |
2/4✓ Branch 0 taken 47635 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47635 times.
✗ Branch 3 not taken.
|
47635 | tmp_table_field = create_tmp_field(thd, tmp_table, item, item->type(), |
| 10444 | nullptr, &from_field, &default_field, | ||
| 10445 | false, false, false, false); | ||
| 10446 | } | ||
| 10447 | |||
| 10448 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53129 times.
|
53129 | if (!tmp_table_field) { |
| 10449 | ✗ | return nullptr; /* purecov: inspected */ | |
| 10450 | } | ||
| 10451 | |||
| 10452 | Field *table_field; | ||
| 10453 | |||
| 10454 |
2/2✓ Branch 0 taken 44850 times.
✓ Branch 1 taken 8279 times.
|
53129 | switch (item->type()) { |
| 10455 | 44850 | case Item::FIELD_ITEM: | |
| 10456 | case Item::TRIGGER_FIELD_ITEM: { | ||
| 10457 | /* | ||
| 10458 | We have to take into account both the real table's fields | ||
| 10459 | and pseudo-fields used in trigger's body. These fields are used to copy | ||
| 10460 | defaults values later inside constructor of the class Create_field. | ||
| 10461 | */ | ||
| 10462 | 44850 | table_field = ((Item_field *)item)->field; | |
| 10463 | 44850 | break; | |
| 10464 | } | ||
| 10465 | 8279 | default: { | |
| 10466 | /* | ||
| 10467 | If the expression is of temporal type having date and non-nullable, | ||
| 10468 | a zero date is generated. If in strict mode, then zero date is | ||
| 10469 | invalid. For such cases no default is generated. | ||
| 10470 | */ | ||
| 10471 | 8279 | table_field = nullptr; | |
| 10472 |
2/2✓ Branch 0 taken 166 times.
✓ Branch 1 taken 250 times.
|
8695 | if (is_temporal_type_with_date(tmp_table_field->type()) && |
| 10473 |
6/6✓ Branch 0 taken 416 times.
✓ Branch 1 taken 7863 times.
✓ Branch 2 taken 45 times.
✓ Branch 3 taken 121 times.
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 8234 times.
|
8695 | thd->is_strict_mode() && !item->is_nullable()) |
| 10474 | 45 | tmp_table_field->set_flag(NO_DEFAULT_VALUE_FLAG); | |
| 10475 | } | ||
| 10476 | } | ||
| 10477 | |||
| 10478 |
2/4✓ Branch 0 taken 53129 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53129 times.
✗ Branch 3 not taken.
|
53129 | assert(tmp_table_field->gcol_info == nullptr && |
| 10479 | tmp_table_field->stored_in_db); | ||
| 10480 | Create_field *cr_field = | ||
| 10481 |
2/4✓ Branch 0 taken 53129 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53129 times.
✗ Branch 3 not taken.
|
53129 | new (thd->mem_root) Create_field(tmp_table_field, table_field); |
| 10482 | |||
| 10483 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53129 times.
|
53129 | if (!cr_field) { |
| 10484 | ✗ | return nullptr; /* purecov: inspected */ | |
| 10485 | } | ||
| 10486 | |||
| 10487 | // Mark if collation was specified explicitly by user for the column. | ||
| 10488 |
2/2✓ Branch 0 taken 44846 times.
✓ Branch 1 taken 8283 times.
|
53129 | if (item->type() == Item::FIELD_ITEM) { |
| 10489 | 44846 | const TABLE *table = table_field->table; | |
| 10490 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44846 times.
|
44846 | assert(table); |
| 10491 | 44846 | const dd::Table *table_obj = | |
| 10492 |
2/2✓ Branch 0 taken 27584 times.
✓ Branch 1 taken 17262 times.
|
44846 | table->s->tmp_table ? table->s->tmp_table_def : nullptr; |
| 10493 | |||
| 10494 |
3/4✓ Branch 0 taken 44796 times.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 44796 times.
✗ Branch 3 not taken.
|
44846 | if (!table_obj && table->s->table_category != TABLE_UNKNOWN_CATEGORY) { |
| 10495 |
1/2✓ Branch 0 taken 44796 times.
✗ Branch 1 not taken.
|
44796 | dd::cache::Dictionary_client::Auto_releaser releaser(thd->dd_client()); |
| 10496 | |||
| 10497 |
4/8✓ Branch 0 taken 44796 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44796 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 44796 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 44796 times.
|
44796 | if (thd->dd_client()->acquire(table->s->db.str, table->s->table_name.str, |
| 10498 | &table_obj)) { | ||
| 10499 | ✗ | return nullptr; /* purecov: inspected */ | |
| 10500 | } | ||
| 10501 |
1/2✓ Branch 0 taken 44796 times.
✗ Branch 1 not taken.
|
44796 | } |
| 10502 | |||
| 10503 | 44846 | cr_field->is_explicit_collation = false; | |
| 10504 |
2/2✓ Branch 0 taken 17312 times.
✓ Branch 1 taken 27534 times.
|
44846 | if (table_obj) { |
| 10505 |
2/4✓ Branch 0 taken 17312 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17312 times.
✗ Branch 3 not taken.
|
17312 | const dd::Column *c = table_obj->get_column(table_field->field_name); |
| 10506 |
2/4✓ Branch 0 taken 17312 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17312 times.
✗ Branch 3 not taken.
|
17312 | if (c) cr_field->is_explicit_collation = c->is_explicit_collation(); |
| 10507 | } | ||
| 10508 | } | ||
| 10509 | |||
| 10510 |
2/2✓ Branch 0 taken 22312 times.
✓ Branch 1 taken 30817 times.
|
53129 | if (item->is_nullable()) cr_field->flags &= ~NOT_NULL_FLAG; |
| 10511 | |||
| 10512 | 53129 | return cr_field; | |
| 10513 | } | ||
| 10514 | |||
| 10515 | 13444313 | const char *get_field_name_or_expression(THD *thd, const Field *field) { | |
| 10516 |
2/2✓ Branch 0 taken 912 times.
✓ Branch 1 taken 13443431 times.
|
13444313 | if (field->is_field_for_functional_index()) { |
| 10517 | 912 | String expression_buffer; | |
| 10518 |
1/2✓ Branch 0 taken 931 times.
✗ Branch 1 not taken.
|
931 | field->gcol_info->print_expr(thd, &expression_buffer); |
| 10519 |
1/2✓ Branch 0 taken 931 times.
✗ Branch 1 not taken.
|
931 | return thd->strmake(expression_buffer.ptr(), expression_buffer.length()); |
| 10520 | 931 | } | |
| 10521 | |||
| 10522 | 13443431 | return field->field_name; | |
| 10523 | } | ||
| 10524 |